我創建了一個用戶控制使用CoerceValueCallback,我的團隊的其他成員簡單地將它放在自己的觀點,然後他們可以動態創建按鈕的ObservrableCollection並綁定到它(帶狀條但它高度定製我們的需求),它處理位置,樣式等它工作得很好,完全符合我們項目的需要,但它只能在初始加載時工作,我做了一些挖掘,並意識到這是因爲我只有一個PropertyChangedCallback在FrameWorkMetaData,我並沒有設立一個回調的CoerceValueCallback所以我做了一些挖掘和建立一個帳戶,但我不知道該怎麼做 - 我想這裏的問題,CoerceValueCallback的方法簽名已經將其返回一個對象,我只是想在列表更改時更新我的按鈕。忽略這個返回值是否安全?也許有些代碼可能會幫助 -如何propertly在自定義WPF用戶控件
這裏是我的PropertyChangedCallback - 被解僱時,他們首先分配按鈕
public static void ButtonListUpdated(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
int count = 0;
var grid = (source as RibbonBarUserControl).ButtonsGrid;
var buttons = e.NewValue as ObservableCollection<Button>;
if (buttons != null)
{
grid.Children.Clear();
foreach (RibbonButton b in buttons)
{
b.Margin = new Thickness(1);
b.Style = (Style)grid.FindResource("ribbonButtonStyle");
ColumnDefinition c = new ColumnDefinition();
grid.ColumnDefinitions.Add(c);
grid.Children.Add(b);
Grid.SetRow(b, 0);
Grid.SetColumn(b, count);
count = ++count;
}
}
}
沒有這裏的名單是CoerceValueCallback
public static object OnButtonListModified(DependencyObject sender, Object baseValue)
{
//What to do here? Can I essentially ignore the returned object and basically
//copy what I am doing in ButtonListUpdated?
return baseValue;
}
我看到一些例子在線他們在哪裏更簡單 - 比如如果生日比結婚年份生日=結婚年份少,當然這有點不同 - 我正在創建按鈕並更新我的控件的UI。
確定 - 感謝您的任何建議!
忍者!謝謝 - 我正在咆哮着錯誤的樹 - 現在你明確指出這一點非常明顯。 – Kenn