美好时光.我在WPF中遇到数据绑定问题.如果我使用绑定:
<TextBlock Text="{Binding Key}" TextTrimming="CharacterEllipsis"
MaxWidth="{Binding ActualWidth, RelativeSource={RelativeSource
AncestorType={x:Type Expander}}, Converter={StaticResource string_cutter_width}}"/>
Run Code Online (Sandbox Code Playgroud)
在下面的代码中,我Markup.IStyle.Connector.Connect在某些计算机上出错.我不明白为什么.如果你遇到这种行为或对此有一些想法.请分享.
<DataGridTemplateColumn Header="{x:Static res:Resources.status_col_header}" Width="1*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DataTemplate.Resources>
<local:Localizer2 x:Key="Localizer2" />
</DataTemplate.Resources>
<Expander Header="{Binding status.Text, Converter={StaticResource Localizer2}}" MouseEnter="Expander_MouseEnter" Tag="{Binding}">
<TreeView x:Name="GTree" ItemsSource="{Binding status.files}" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
<TreeView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" ClipToBounds="False" IsHitTestVisible="true" Margin="1">
<StackPanel Orientation="Vertical">
<StackPanel.Resources>
<local:string_cutter_width x:Key="string_cutter_width" />
</StackPanel.Resources>
<TextBlock Text="{Binding Key}" TextTrimming="CharacterEllipsis" MaxWidth="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type Expander}}, Converter={StaticResource string_cutter_width}}"/>
<TextBlock Text="{Binding Value}" TextTrimming="CharacterEllipsis" MaxWidth="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type Expander}}, Converter={StaticResource string_cutter_width}}"/>
<!--<TextBlock Text="{Binding Key}" TextTrimming="CharacterEllipsis"/>
<TextBlock Text="{Binding …Run Code Online (Sandbox Code Playgroud) 请帮助我弄清楚如何在 WPF 的 DataGrid 中使用 ComboBoxColumn。我正在尝试创建一个设备列表,其中每个设备在“日志”字段中都有动态状态列表。
<DataGrid AutoGenerateColumns="False" Margin="12,6,12,12" Name="dataGrid1" Grid.Row="1" SelectionUnit="FullRow">
<DataGrid.Columns>
...
<DataGridComboBoxColumn Header="Log"
ItemsSource="{Binding log, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Device}}}"/>
</DataGrid.Columns>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
public partial class MainWindow : Window
{
public ObservableCollection<Device> devices;
...
}
public MainWindow()
{
...
dataGrid1.ItemSource = devices;
}
public class Device : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public Device() {log = new ObservableCollection<string>();}
...
private ObservableCollection<string> _log;
public ObservableCollection<string> log …Run Code Online (Sandbox Code Playgroud)