2009-08-21 30 views
10

Tengo un WPF UserControl que contiene un botón de eliminación, me gustaría pasar el UserControl completo como el parámetro de comando.wpf usercontrol, parámetro de comando bind del botón al control de usuario principal

Actualmente el enlace se establece en CommandParameter = "{Binding RelativeSource = {RelativeSource Self}}" que me da el botón, pero ¿cómo puedo obtener el control completo?

¿Alguien puede ayudarme por favor?

Saludos,

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"> 
<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> 

Respuesta

6

agrietado ...

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