問題
我有一個ComboBox
和MainWindow
一個ToggleButton
具有雙向綁定自己的SelectedIndex
和IsChecked
性質,分別。它們綁定的屬性是DependencyProperties(DP),我在setter上有一個斷點,但調試器從來沒有停止過。我應該注意,這些綁定應該在DP上的初始者工作並且轉換器也起作用。 VS的輸出窗口也不值得關注。雙向數據綁定不更新ComboBox&ToggleButton?
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>
代碼隱藏(DPS)
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));
嘗試在你的依賴屬性制定者去除多餘的東西。只需調用'SetValue'並再次拍攝。 – PoweredByOrange
仍然不會中斷。它是否應該打破制定者的標準?因爲調試器沒有中斷getters?我要創建一個新的測試項目,看看它是否應該。 –
轉換器是否被調用?請注意,當您在綁定中使用'Path'和'ElementName'時,它將在指定元素中查找該路徑,而不是在DataContext中查找。所以在你的CheckBox的情況下,它會查找'mwa.SortDirection'。無論如何,「mwa」是什麼?它是你的'MainWindow'嗎? – PoweredByOrange