C# 如何按内容设置DataGridTemplateColumn的宽度?
我是WPF的新手,我的问题是有没有办法通过这个列中最宽的项目来设置列的宽度 当我运行我的应用程序时,此列如下所示C# 如何按内容设置DataGridTemplateColumn的宽度?,c#,wpf,C#,Wpf,我是WPF的新手,我的问题是有没有办法通过这个列中最宽的项目来设置列的宽度 当我运行我的应用程序时,此列如下所示 Word根据这一点,您不能直接在XAML中完成它。它需要一些代码隐藏或附加行为,因为组合框在检索其收集的项目之前解析其宽度。您是否尝试设置width=Auto?类似于@trix的东西它没有帮助。。。它通过标题设置宽度。。。据我所知,有没有应用过什么风格?@AlekseyTimoshchenko:你有没有尝试在一个新的空白应用程序中复制这种风格? <DataGridTempla
Word
根据这一点,您不能直接在XAML中完成它。它需要一些代码隐藏或附加行为,因为组合框在检索其收集的项目之前解析其宽度。您是否尝试设置width=Auto
?类似于@trix的东西它没有帮助。。。它通过标题设置宽度。。。据我所知,有没有应用过什么风格?@AlekseyTimoshchenko:你有没有尝试在一个新的空白应用程序中复制这种风格?
<DataGridTemplateColumn Header="{x:Static res:Resources.geo_calib_folder}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="Cb_geometry_calibration"
ToolTip="{x:Static res:Resources.tooltip_chosen_geometry_calibration_folder}"
PreviewMouseWheel="Cb_PreviewMouseWheel"
SelectionChanged="Cb_geometry_calibration_SelectionChanged"
ItemsSource="{Binding Path=GeoCalibrationFolders}"
SelectedItem="{Binding Path=SelectedGeoCalibrationFolder}"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock
Text="{Binding Path=UIRepresentation}" />
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.Style>
<Style TargetType="ComboBox">
<Style.Triggers>
<DataTrigger Binding="{Binding IsGeoCalibFolderBold}"
Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="FontWeight" Value="Normal"/>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>