屏幕上不可見的行將無法使用此方法着色,因爲它們被虛擬化並且實際上不存在。在下面IM綁定屬性的樣式IsRed(從與它的數據網格把這個的資源)
<Style
TargetType="{x:Type dg:DataGridRow}"
BasedOn="{StaticResource {x:Type dg:DataGridRow}}">
<Style.Triggers>
<DataTrigger
Binding="{Binding ElementName=self, Path=IsRed}"
Value="True">
<Setter
Property="Background"
Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
變成紅色,其默認的顏色之間的行我有我的窗體上的依賴屬性所謂IsRed,這也可能是實現INotifyPropertyChanged(依賴屬性通知他們的變化)
public Boolean IsRed {
get { return (Boolean)GetValue(IsRedProperty); }
set { SetValue(IsRedProperty, value); }
}
// Using a DependencyProperty as the backing store for IsRed. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsRedProperty =
DependencyProperty.Register("IsRed", typeof(Boolean), typeof(Window1), new UIPropertyMetadata(false));
然後在我的XAML我有聲明頂部
<Window
x:Class="Grids.Window1"
x:Name="self">
任何財產
這意味着我可以與元素的名稱綁定引用它(的技術我覺得有用)
隨着代碼爲香港專業教育學院列出您所有的按鈕點擊將要做的是
private void Button_Click(object sender, RoutedEventArgs e) {
IsRed = !IsRed;
}
你能提供一個關於這個ViewModel的例子嗎?當涉及到綁定屬性時,我仍然不太好。 – KenNY 2010-01-13 01:44:17
http://sites.google.com/site/wpfprojects/下載彩色行示例,並將此問題標記爲已回答。可能還有其他一些項目,您可能也會喜歡看看 – 2010-01-13 03:36:25
+1,因爲拼寫的顏色是'u',哦,並且感謝這個例子。 – Grokodile 2010-04-22 15:55:32