根控制模板

时间:2010-07-21 14:00:12

标签: wpf silverlight

我有自定义控件名为Frame(公共类Frame:ContentControl,IDisposable)。构造函数中的框架定义DefaultStyleKey = typeof(Frame);和Frame模板在Generic.xaml资源中。现在在其他一些项目中我使用Silverlight.Controls中的框架,如果我设置我的主页面,根元素就是这样的框架

<ShellFrame:Frame x:Class="Modules.Adresar.MainPage"
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:s="clr-namespace:Modules.Adresar.ViewModel"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ShellFrame="clr-namespace:Silverlight.Controls;assembly=Silverlight.Controls" mc:Ignorable="d"
DataContext="{Binding Source={StaticResource VMLocator}, Converter={StaticResource VMIndexerConverter}, ConverterParameter=AdresarVM}"
              d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type=s:AdresarViewModel}" x:Name="MainFrame">

<Grid x:Name="LayoutMain">


</Grid>

我无法编辑框架模板。混合显示已禁用的编辑模板菜单项。但是如果我将框架放在普通用户控件的布局根网格中,那么一切都很好......就像这样

<UserControl
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"
xmlns:ShellFrame="clr-namespace:Silverlight.Controls;assembly=Silverlight.Controls"
mc:Ignorable="d"
x:Class="Adresar.Test"
d:DesignWidth="640" d:DesignHeight="480">

<Grid x:Name="LayoutRoot">
    <ShellFrame:Frame Content="Frame" HorizontalAlignment="Left" Margin="72,136,0,0" VerticalAlignment="Top"/>
</Grid>

enybody知道为什么会这样吗?谢谢!

1 个答案:

答案 0 :(得分:0)

将Frame控件更改为基于UserControl而不是ContentControl,应该可以解决您在Blend中看到的行为。我不确定你是如何使用你的控件的,但是如果你不能使用UserControl,你可能想要包含一些上下文。

相关问题