The following code on displays the {Binding text} and the dependency property for Sprites does not run the propertyvaluechanged for text runs but not for sprites.

<ItemsControl x:Name="AnswerListBox" ItemsSource="{Binding Answers}" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <local:spriteRadioButton Text="{Binding text}" Sprites="{Binding Path=DataContext.UISprites, ElementName=questionField}" GroupName="{Binding Path=DataContext.QuestionTitle, ElementName=questionField}" IsChecked="{Binding selected}" />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <toolkit:WrapPanel/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

if i don't use an itemspaneltemplate then the properties work as expected.

有帮助吗?

解决方案

At the moment you're using the default "OneWay" binding mechanism. This means that your object can update the UI but the UI cannot update the object.

Your binding should use "TwoWay" binding in order to allow the UI to notify the object of changes:

<DataTemplate>
    <local:spriteRadioButton Text="{Binding text,Mode=TwoWay}" Sprites="{Binding Path=DataContext.UISprites, ElementName=questionField,Mode=TwoWay}" GroupName="{Binding Path=DataContext.QuestionTitle, ElementName=questionField,Mode=TwoWay}" IsChecked="{Binding selected,Mode=TwoWay}" />
</DataTemplate>

Keep in mind, these changes will update your Answers object. If you want to change the Answers object itself this too will need to be marked as TwoWay binding as well.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top