7
任何人都知道那說明與數據網格項目路由操作的卡利或卡利Micro Framework的例子很好的代碼示例?Silverlight中,卡利,操作和DataGrid中
任何人都知道那說明與數據網格項目路由操作的卡利或卡利Micro Framework的例子很好的代碼示例?Silverlight中,卡利,操作和DataGrid中
此示例附着到在數據網格的每一行的動作。該操作在作爲整個視圖的datacontext的視圖模型上處理。這是建立在微型,但語法是相同的。這不使用基於約定的數據綁定。
視圖的相關部分是:
<sdk:DataGrid ItemsSource="{Binding Source}"
AutoGenerateColumns="False">
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn Header="Action">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="Do!"
cm:Message.Attach="Remove($dataContext)" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTextColumn Binding="{Binding Text}" />
<sdk:DataGridTextColumn Binding="{Binding More}" />
<sdk:DataGridTextColumn Binding="{Binding Stuff}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
和相應的視圖模型看起來是這樣的:
public class ShellViewModel : IShell
{
public ShellViewModel()
{
Source = new ObservableCollection<MyRow>(
new[]
{
new MyRow {Text = "A1", More = "B", Stuff = "C"},
new MyRow {Text = "A2", More = "B", Stuff = "C"},
new MyRow {Text = "A3", More = "B", Stuff = "C"},
new MyRow {Text = "A4", More = "B", Stuff = "C"},
new MyRow {Text = "A5", More = "B", Stuff = "C"},
}
);
}
public void Remove(MyRow row)
{
Source.Remove(row);
}
public ObservableCollection<MyRow> Source { get; set; }
}
public class MyRow
{
public string Text { get; set; }
public string More { get; set; }
public string Stuff { get; set; }
}
特殊參數$ DataContext的是這裏討論: http://caliburn.codeplex.com/wikipage?title=Parameters&referringTitle=Documentation
你應該標記答案,爲社區的其他人提供反饋。 – RyBolt 2010-10-18 16:22:24
剛剛做到了。謝謝。 – BuddyJoe 2010-10-22 02:44:20