내 레거시 프로젝트에서 코드 숨김을 통해 바인딩 속성 이름을 가져와야합니다. XAML :
<DataGridTextColumn MinWidth="180" MaxWidth="180" Width="Auto" Binding="{Binding ConfigObject.MAC_Descr}" Header="Descr" Foreground="Black">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Padding" Value="6,12" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsDirty}" Value="True">
<Setter Property="TextBlock.Background" Value="{StaticResource IsDirtyColor}" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="TextBox">
<Setter Property="Background" Value="White"/>
<Setter Property="Padding" Value="5,12"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
</DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
내가 사용하는 이벤트 :
private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
DataGridCell row = sender as DataGridCell;
if (row == null) return;
// Binding column name??
string bindingExpression = row.GetBindingExpression(TextBlock.TextProperty).ResolvedSourcePropertyName;
}
}
기본적으로 위의 경우 "MAC_Descr"을 검색해야합니다. 도움이 필요하세요?
다음과 같이 시도해 볼 수 있습니다.
private void OnCellDoubleClick(object sender, MouseButtonEventArgs e)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
if (!(sender is DataGridCell cell)) return;
if (!(cell.Column is DataGridTextColumn column)) return;
if (!(column.Binding is Binding binding)) return;
var path = binding.Path.Path;
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다