问题
我分别对它们的和ComboBox
属性进行ToggleButton
了MainWindow
双向绑定。它们绑定的属性是 DependencyProperties (DP),我在设置器上有一个断点,但调试器永远不会停止。我应该注意,绑定应该像 DP 上的 Initialisers 一样工作,并且转换器也可以工作。VS 的输出窗口也没什么好担心的。SelectedIndex
IsChecked
XAML
<ToggleButton x:Name="tbSortDirection" Width="25" IsChecked="{Binding Path=SortDirection,Converter={StaticResource LDB},Mode=TwoWay,ElementName=mwa,UpdateSourceTrigger=PropertyChanged}">
<ed:RegularPolygon Fill="#FF080808" Height="5" UseLayoutRounding="True" Margin="-2,0,0,0" PointCount="3" Width="6"/>
</ToggleButton>
<ComboBox x:Name="cbSort" Width="100" VerticalAlignment="Stretch" Margin="-5,0,0,0" SelectedIndex="{Binding SelSortIndex,Mode=TwoWay,ElementName=mwa,UpdateSourceTrigger=PropertyChanged}" IsSynchronizedWithCurrentItem="True" >
<ComboBoxItem Content="a"/>
<ComboBoxItem Content="b"/>
<ComboBoxItem Content="v"/>
<ComboBoxItem Content="f"/>
</ComboBox>
代码隐藏 (DP)
public ListSortDirection SortDirection
{
get { return (ListSortDirection)GetValue(SortDirectionProperty); }
set // BreakPoint here
{
MessageBox.Show("");
SetValue(SortDirectionProperty, value);
UpdateSort();
}
}
public static readonly DependencyProperty SortDirectionProperty =
DependencyProperty.Register("SortDirection", typeof(ListSortDirection), typeof(MainWindow), new PropertyMetadata(ListSortDirection.Ascending));
public int SelSortIndex
{
get { return (int)GetValue(SelSortIndexProperty); }
set // BreakPoint here
{
MessageBox.Show("");
SetValue(SelSortIndexProperty, value);
UpdateSort();
}
}
public static readonly DependencyProperty SelSortIndexProperty =
DependencyProperty.Register("SelSortIndex", typeof(int), typeof(MainWindow), new PropertyMetadata(1));