【问题标题】:wpf usercontrol, bind command parameter of button to the parent usercontrolwpf usercontrol,将按钮的命令参数绑定到父用户控件
【发布时间】:2010-11-21 14:54:58
【问题描述】:

我有一个包含删除按钮的 WPF UserControl,我想将整个 UserControl 作为 CommandParameter 传递。

当前绑定设置为 CommandParameter="{Binding RelativeSource={RelativeSource Self}}" 这给了我按钮,但我怎样才能获得整个控件?

有人可以帮忙吗?

干杯,

安迪

<UserControl x:Class="GTS.GRS.N3.Controls.LabelledTextBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100" />
        <ColumnDefinition Width="155" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Label Name="label" HorizontalAlignment="Left" Width="96">Label</Label>
    <TextBox Name="textBox" Grid.Column="1" />
    <Button Grid.Column="2" Style="{DynamicResource CloseButton}" Command="{Binding RemoveCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self}}" Visibility="{Binding RemoveVisible}"></Button>
</Grid>
</UserControl>

【问题讨论】:

    标签: wpf binding user-controls


    【解决方案1】:

    破解它...

    <Button 
        Grid.Column="2" 
        Style="{DynamicResource CloseButton}"
        Command="{Binding RemoveCommand}"
        CommandParameter="{Binding RelativeSource=
            {RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" 
        Visibility="{Binding RemoveVisible}" 
        />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 1970-01-01
      • 2013-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多