Cases when binding are automatically disabled

Today I ran into a problem that reminded me that snaps are automatically disabled in some cases. I'm not sure, but here is the script -

I am attaching a menu item tied to a property (implementing INotifyPropertyChanged), for example:

IsChecked="{Binding Path=DisplayLongUnit, Mode=TwoWay}"

Now in the processed event handler, I update its value IsCheckedafter checking some state like this -

If( condition == true){menuItem.IsChecked = true}

Will the binding now be bound or will it be lost? (I remember reading somewhere that he would be lost).

Are there any scenarios in which the bindings will be automatically disconnected?

How I found out is mentioned here -

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/08d6e4c4-47ab-44f3-b19a-c0ab872fb1a8

+3
4

, : , . XAML. ( ):

<Window xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase">  

. , TextBox Text:

<TextBox Text={Binding FirstName, diagnostics:PresentationTraceSources.TraceLevel=High} />  

, "" Visual Studio , , " ", .

, , , . .

+5

?

IsChecked="{Binding Path=DisplayLongUnit, Mode=TwoWay}"
0

:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/4165daed-2eaf-450b-a082-63d79ff9fd3e

You might want to make the binding mode in two ways (this way your property will also be updated, and I don't know what the default value for IsChecked is, but it is always best to be explicit) or just change the DisplayLongUnit property instead of the IsChecked property.

0
source

Remember to set the value "IsCheckable" to true. If this is not the case, TwoWay binding will not work. The following MenuItem interface works for me (without code):

<MenuItem Header="Select sense" ItemsSource="{Binding Path=AvailableSenses}" >
    <MenuItem.ItemContainerStyle>
        <Style TargetType="MenuItem">
            <Setter Property="Header" Value="{Binding Path=Sense.English}" />
            <Setter Property="IsCheckable" Value="True" />
            <Setter Property="IsChecked" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
        </Style>
    </MenuItem.ItemContainerStyle>
</MenuItem>
0
source

Source: https://habr.com/ru/post/1758205/


All Articles