您好我想作一个简单的用户控件用户控件可混合性WP7
<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();
}
}
现在所有的作品,但不是共混......和苹果酒,我可以”看不到“测试的消息”
有一个可行的办法:)没有涉及的xmlns:MyControl = ...
你必须更清楚你定义的“Blendable”。 **精确**不起作用。 –
我的意思是我在设计时看到在运行应用程序之前在屏幕上显示“在消息中测试”消息:) – LXG
您错误地理解了依赖属性如何完全工作。 –