I want a column in my datagrid to display both text and a small ellipsis "..." button - similar to what you see in the Visual Studio property grid. Here is a mockup of the datagrid column I'm trying to build:
我想在我的数据网格中的一列显示文本和一个小的省略号“...”按钮 - 类似于您在Visual Studio属性网格中看到的。这是我正在尝试构建的datagrid列的模型:
When the user clicks the ellipsis button, I will display a custom picker dialog and then in the text section of the column, display what I can of the comma sepatated values (i.e. string) returned from the dialog.
当用户单击省略号按钮时,我将显示一个自定义选择器对话框,然后在该列的文本部分中,显示我可以从对话框返回的逗号分隔值(即字符串)。
How do I get a datagrid column to contain both text and button as I have mocked up here?
我如何得到一个datagrid列包含文本和按钮,因为我在这里模拟了?
3 个解决方案
#1
1
Search for DataGridTemplateColumn.
搜索DataGridTemplateColumn。
#2
0
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.Resources>
<DataTemplate x:Key="mDataTemplate">
<Button Margin="10,10,0,0" >
<Button.Content>
<Grid x:Name="ButtonGrid" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock />
<Ellipse />
</Grid>
</Button.Content>
</Button>
</DataTemplate>
</Grid.Resources> </Grid>
#3
0
You have to use a DataGridTemplateColumn
.
您必须使用DataGridTemplateColumn。
Sample code:
示例代码:
<DataGrid>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Your header">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DockPanel>
<Button DockPanel.Dock="Right">...</Button>
<TextBlock Text="{Binding YourProperty}"></TextBlock>
</DockPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
#1
1
Search for DataGridTemplateColumn.
搜索DataGridTemplateColumn。
#2
0
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.Resources>
<DataTemplate x:Key="mDataTemplate">
<Button Margin="10,10,0,0" >
<Button.Content>
<Grid x:Name="ButtonGrid" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock />
<Ellipse />
</Grid>
</Button.Content>
</Button>
</DataTemplate>
</Grid.Resources> </Grid>
#3
0
You have to use a DataGridTemplateColumn
.
您必须使用DataGridTemplateColumn。
Sample code:
示例代码:
<DataGrid>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Your header">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DockPanel>
<Button DockPanel.Dock="Right">...</Button>
<TextBlock Text="{Binding YourProperty}"></TextBlock>
</DockPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>