【发布时间】:2010-10-26 16:53:08
【问题描述】:
我想要一个名为 Segmented Panel 的用户控件,其中包含 3 个按钮,我想从 XAML 屏幕修改它们的名称 (Title1/2/3)。
主页 XAML:
<local:SegmentedControl HorizontalAlignment="Left" Margin="43,62,0,0" x:Name="segmentedControl1" VerticalAlignment="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); }
}
在表达式混合中,我打开分段面板,选择 button1,在内容中我尝试选择 Data Context 和 Element Value,然后向下滚动以选择“Title1” ,但是当我编译它时,按钮的内容永远不会改变。
谁能帮帮我?
【问题讨论】:
-
我不明白。您正在向 StackPanel 添加附加属性,但您的类型是 SegmentedControl?你的意思是在 typeof(SegmentedControl) 上声明你的依赖属性吗?
标签: silverlight xaml windows-phone-7