views:

1255

answers:

2

Hi,

I've got a WPF UserControl which contains a remove button, I'd like to pass the entire UserControl as the CommandParameter.

Currently the binding is set to CommandParameter="{Binding RelativeSource={RelativeSource Self}}" which gives me the button, but how can I get the entire control?

Can anyone assist please?

Cheers,

Andy

<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"&gt;
<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>
A: 

Cracked it ...

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

wow...thank's sir you dolve my probelem. I'm implement your code to button inside the datatemplate

<Button Content="Edt">
<i:Interaction.Triggers>
       <i:EventTrigger EventName="Click">
             <cmd:EventToCommand Command="{Binding Source={StaticResource Locator}, Path=Category.FillInputCommand}"
              CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dg:DataGrid}}}"
              PassEventArgsToCommand="True"/>
        </i:EventTrigger>
  </i:Interaction.Triggers>

before it, i just using command parameter like this CommandParameter="{Binding SelectedItem, ElementName=mydatagridenter code here

Gus Leo