【发布时间】:2011-09-28 16:51:39
【问题描述】:
您好,我想做一个简单的用户控件
<UserControl x:Class="TestDependencyProps.controls.TestControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
d:DesignHeight="480" d:DesignWidth="480">
<Grid x:Name="LayoutRoot" >
<TextBlock Height="30" Margin="31,140,27,0" Name="textBlock1" Text="{Binding testMessage}" VerticalAlignment="Top" />
</Grid>
</UserControl>
后面的代码:
public partial class TestControl : UserControl
{
public string testMessage
{
get { return (string)GetValue(testMessageProperty); }
set { SetValue(testMessageProperty, value); }
}
public static readonly DependencyProperty testMessageProperty =
DependencyProperty.Register("testMessage", typeof(string), typeof(TestControl),new PropertyMetadata("test in a message",null)
);
public TestControl()
{
InitializeComponent();
}
}
现在一切正常,但不可混合......在 Cider 中我看不到“消息中的测试”
有一种方法可以工作 :) 不涉及 xmlns:MyControl=...
【问题讨论】:
-
您必须更清楚您对“可混合”的定义。 精确的是行不通的。
-
我的意思是我在设计时看到,在运行应用程序之前,屏幕上出现“test in a message”消息:)
-
你完全误解了依赖属性是如何工作的。
标签: xaml windows-phone-7 user-controls