这是我的问题。我在RadTileViewItem的内容部分中有一个DataTemplate。每个ViewItem都有一个具有各种属性的模型对象。 DataTemplate内部是一个按钮。单击此按钮时,我希望能够访问RadTileViewItem的模型对象。我该怎么做呢?我不知道我怎么知道每个按钮所在的内容是什么,以获得它的模型对象。
视图模型:
class TCardViewModel
{
private ObservableCollection<TCardBase> items;
public TCardViewModel()
{
List<TCardBase> itemsSource = new List<TCardBase>();
CFETSDBContainer ctx = new CFETSDBContainer();
foreach (var incident in ctx.INCIDENTs)
{
itemsSource.Add(new TCardBase()
{
IncidentName = incident.IncidentName,
Desginator = "Desig",
Location = "Lat:"+incident.Latitude+",Lon:"+incident.Longitude,
});
}
this.items = new ObservableCollection<TCardBase>(itemsSource);
}
public ObservableCollection<TCardBase> Items
{
get
{
return items;
}
}
}
<telerik:RadTileView Name="MainRadTileView"
IsItemDraggingEnabled="{Binding ElementName=IsItemDraggingEnabledOption,Path=IsChecked}"
ItemsSource="{Binding Items}"
ContentTemplateSelector="{StaticResource TCardTemplateSelector}"
ItemTemplate="{StaticResource headerTemplate}"
MaximizeMode="{Binding ElementName=MaximizeModeOption,Path=SelectedItem}"
PreservePositionWhenMaximized="{Binding ElementName=PreservePositionWhenMaximizedOption,Path=IsChecked}"
TileStateChanged="tileView1_TileStateChanged"
TileStateChangeTrigger="{Binding ElementName=StateChangeOption, Path=SelectedItem}"/>
<DataTemplate x:Key="IncidentContentTemplate">
<telerik:RadFluidContentControl ContentChangeMode="Manual"
State="Normal"
TransitionDuration="0:0:.5">
<telerik:RadFluidContentControl.Content>
<Border Background="Red">
<Grid Margin="20 10">
<StackPanel>
<TextBlock Margin="0 0 0 5"
FontFamily="Segoe UI"
FontSize="24"
FontWeight="Light"
Foreground="#fff"
Text="Designator" />
<TextBlock FontSize="14"
Foreground="{telerik:Windows8Resource ResourceKey=AccentBrush}"
Text="{Binding Desginator}" />
<Border Height="2"
Margin="0 5"
Background="{telerik:Windows8Resource ResourceKey=AccentBrush}" />
<TextBlock Margin="0 0 0 5"
FontFamily="Segoe UI"
FontSize="24"
FontWeight="Light"
Foreground="#fff"
Text="Location" />
<TextBlock FontSize="14"
Foreground="{telerik:Windows8Resource ResourceKey=AccentBrush}"
Text="{Binding Location}" />
</StackPanel>
</Grid>
</Border>
</telerik:RadFluidContentControl.Content>
<telerik:RadFluidContentControl.LargeContent>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="360" />
<ColumnDefinition Width="160" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- <Image Grid.ColumnSpan="3"
Source="{Binding Image}"
Stretch="None" />-->
<Button Width="200" Height="200" Content="View" Click="LoadTCard_Clicked"></Button>
<StackPanel Margin="35 205 0 0" Orientation="Horizontal">
<TextBlock FontSize="30"
Foreground="#FFFFFF"
Text="{Binding Desginator}" />
<TextBlock FontSize="30"
Foreground="#FFFFFF"
Text="" />
</StackPanel>
<StackPanel Grid.Column="1"
Margin="15 155 0 0"
Orientation="Horizontal">
<TextBlock FontFamily="Segoe UI"
FontSize="14"
Foreground="#FFFFFF"
Text="{Binding Desginator}" />
<TextBlock FontFamily="Segoe UI"
FontSize="14"
Foreground="#FFFFFF"
Text="@trips.com" />
</StackPanel>
<StackPanel Grid.Column="2" Margin="70 50 0 0">
<TextBlock Margin="0 0 0 5"
FontFamily="Segoe UI"
FontSize="14"
Foreground="{telerik:Windows8Resource ResourceKey=AccentBrush}"
Text="2011 Oct 28th, 2011 Nov 3th" />
<TextBlock FontFamily="Segoe UI"
FontSize="14"
Foreground="{telerik:Windows8Resource ResourceKey=AccentBrush}"
Text="1011 Nov 11th, 2011 Dec 2nd" />
<TextBlock Margin="0 72 0 0"
FontFamily="Segoe UI"
FontSize="14"
Foreground="{telerik:Windows8Resource ResourceKey=AccentBrush}"
Text="{Binding IncidentName}" />
<TextBlock Margin="0 74 0 0"
FontFamily="Segoe UI"
FontSize="14"
Foreground="{telerik:Windows8Resource ResourceKey=AccentBrush}"
Text="{Binding Location}" />
</StackPanel>
</Grid>
</telerik:RadFluidContentControl.LargeContent>
</telerik:RadFluidContentControl>
</DataTemplate>
谢谢。