문제

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