开发者

WP7 Custom User Control Property

I want a user control called Segmented Panel that contains 3 buttons of which I want to modify their names (Title1/2/3) from a XAML screen.

MainPage XAML:

<local:SegmentedControl HorizontalAlignment="Left" Margin="43,62,0,0" x:Name="segmentedControl1" VerticalAli开发者_运维知识库gnment="Top" Title1="ENTER BUTTON NAME HERE" Title2="blah.." Title3="Last Button" Loaded="segmentedControl1_Loaded" />

SegmentedControl XAML.CS:

public static readonly DependencyProperty Title1Property
        = DependencyProperty.RegisterAttached("Title1", typeof(String), typeof(StackPanel),
        new PropertyMetadata(""));

    public static void SetTitle1(UIElement element, String value) {
        element.SetValue(Title1Property, value);
    }
    public static string GetTitle1(UIElement element) {
        return (string)element.GetValue(Title1Property);
    }

    public string Title1 {
        get { return GetValue(Title1Property).ToString(); }
        set { SetValue(Title1Property, value); }
    }

In expression blend I open up the Segmented Panel, choose button1, in Content I tried chosing both Data Context and Element Value, then scrolling down to choose "Title1", but when I compile it, the button's contents never changes.

Can anybody help me out?


as John Gardner suggests, you have to write ...typeof(SegmentedControl) in your dependency property implementation and then one have to bind the property to the appropiate UI element!

For example:

<local:SegmentedControl HorizontalAlignment="Left" Margin="43,62,0,0" x:Name="segmentedControl1" VerticalAlignment="Top" Title1="{Binding Title1}" ... Loaded="segmentedControl1_Loaded" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜