开发者

Custom control property - Binding problem

开发者 https://www.devze.com 2023-02-15 01:01 出处:网络
I have areally wierd problem when i\'m using some simple custom control i\'ve built: this is the custom control code :

I have areally wierd problem when i'm using some simple custom control i've built: this is the custom control code :

public partial class ToolButton : Button
{
    public string ToolID
    {
        get { return (string)GetValue(ToolIDProperty); }
        set { SetValue(ToolIDProperty, value); }
    }

   public static readonly DependencyProperty ToolIDProperty =
   DependencyProperty.Register("ToolID", typeof(string), typeof(ToolButton), new    UIPropertyMetadata(""));


    public ToolButton()
    {
        InitializeComponent();
    }
}

Now when i'm trying to ude this custom control in the main window like that :

<ItemsControl Margin="100" ItemsSource="{Binding Path=Students}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                   <customControls:ToolButton Height="100" Width="100" Margin="10" Cont开发者_StackOverflowent="{Binding Value.Name}"/> 
                                 </DataTemplate>
             </ItemsControl.ItemTemplate>
        </ItemsControl>

And the binding doesn't work !!

but when i'm using simple button the binding works excellent..

is someone faced similliar problem ??

Thanks...


put the following line into your ToolButton's constructor:

this.DataContext = this;
0

精彩评论

暂无评论...
验证码 换一张
取 消