2009-08-21 16 views
10

Ich habe eine WPF UserControl, die eine Schaltfläche zum Entfernen enthält, möchte ich das gesamte UserControl als CommandParameter übergeben.wpf usercontrol, Bindebefehl Parameter der Schaltfläche an die Eltern usercontrol

Momentan ist die Bindung auf CommandParameter = "{Binding RelativeSource = {RelativeSource Self}}" gesetzt, was mir die Schaltfläche gibt, aber wie bekomme ich das gesamte Steuerelement?

Kann mir bitte jemand helfen?

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

Antwort

6

es Gebrochene ...

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