我有使用MVVM架構編寫的WPF應用程序,所以我有Model,View和ViewModel。我的視圖中有一個DataGrid
,其中包含Product
的列表(包含幾個字段:名稱,餘額等)。打開新視圖單擊DataGrid元素(WPF xaml應用程序)
我想添加額外的窗口/視圖,單擊DataGrid
中的元素後會出現該窗口/視圖。可能嗎?如果是這樣,怎麼樣?
我很喜歡xaml代碼,而不是像button1_Click
這樣的東西。
這就是我目前的樣子:
<Window ...
Height="600" Width="800"
WindowState="Maximized">
<Grid>
<DataGrid AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserResizeRows="False"
IsReadOnly="True"
SelectionMode="Single"
SelectionUnit="FullRow"
ItemsSource="{Binding Path=Products}"
SelectedItem="{Binding Path=CurrentProduct, Mode=TwoWay}"
>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=ProductName}"
Header="Product Name"
Width="*" />
<DataGridTextColumn Binding="{Binding Path=Balance}"
Header="Balance"
Width="Auto" />
...
</DataGrid.Columns>
</DataGrid>
</Grid>
所以......你要調用打開另一個視圖命令從你的datagrid點擊,我說得對嗎? – Jose
@Kirenenko歡迎任何想法。使用命令也可以。 –
你也可以看看DataGrid.RowDetailsTemplatel的這個教程:http://www.wpftutorial.net/datagrid.html – Ugur