我正在尝试将自定义内容控件类从 WinRT 应用程序移植到 Windows Phone 8 应用程序,但我无法弄清楚如何完成它。我基本上想移植如下内容:
菜单面板.cs
public sealed class MenuPanel : ContentControl
{
#region ContentVisibility
/// <summary>
/// ContentVisibility Dependency Property
/// </summary>
public static readonly DependencyProperty ContentVisibilityProperty =
DependencyProperty.Register(
"ContentVisibility",
typeof(Visibility),
typeof(MenuPanel),
new PropertyMetadata(Visibility.Visible, null));
/// <summary>
/// Gets or sets the ContentVisibility property
/// </summary>
public Visibility ContentVisibility
{
get { return (Visibility)GetValue(ContentVisibilityProperty); }
set { SetValue(ContentVisibilityProperty, value); }
}
#endregion
... Lots more, but truncated for brevity
}
泛型.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Expansion.WinRT.Controls">
<Style TargetType="local:MenuPanel">
<Setter Property="ContentVisibility" Value="Visible" />
<Setter Property="EnableVisibility" Value="Collapsed" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:MenuPanel">
<Grid>
<Border BorderBrush="#33FFFFFF" BorderThickness="16" CornerRadius="1" />
<Border BorderBrush="#4CFFFFFF" BorderThickness="8" CornerRadius="1" Margin="4" />
<Border BorderBrush="White" Background="#26FFFFFF" BorderThickness="2" CornerRadius="1" Margin="7" Padding="3">
<StackPanel>
<ContentPresenter
Visibility="{TemplateBinding ContentVisibility}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}" />
<Button
Name="EnableButton"
Visibility="{TemplateBinding EnableVisibility}"
BorderBrush="Transparent"
Content="+"
FontSize="40"
Padding="0,-10,0,0"
HorizontalAlignment="Center"
Width="70" />
</StackPanel>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
主页.xaml
...
<local:MenuPanel Name="MainMenuPanel" Width="520" VerticalAlignment="Center">
<StackPanel>
<StackPanel Name="StartMenu" Visibility="Visible">
<Button Name="NewGameButton" Content="New Game" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="Transparent" FontSize="30" />
<Button Name="LoadGameButton" Content="Load Game" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="Transparent" FontSize="30" />
<Button Name="OptionsButton" Content="Options" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="Transparent" FontSize="30" />
</StackPanel>
</StackPanel>
</local:MenuPanel>
...
我看了一下http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.controls.contentcontrol(v=vs.105).aspx但它没有多大帮助。