[英]Create HyperlinkButton with text wrapping in code behind (Windows Phone 8)
I have the following xaml snippet that I need to create in code behind. 我有以下xaml代码段,需要在后面的代码中创建。 Is this possible to do? 这可能吗?
<HyperlinkButton Name="hyperlinkButton1" NavigateUri="http://www.google.com" Margin="0" Padding="0">
<HyperlinkButton.Template>
<ControlTemplate TargetType="HyperlinkButton">
<Border BorderThickness="0" Padding="0" Margin="0">
<StackPanel Margin="0">
<Image Source="/Assets/Logo.png" Margin="0"/>
<TextBlock VerticalAlignment="Center" Text="Go to View.xaml" Foreground="Green"/>
</StackPanel>
</Border>
</ControlTemplate>
</HyperlinkButton.Template>
</HyperlinkButton>
You can put the xaml above into a long string (start with @"
to have a multi-line string in C#) and then call XamlReader.Load( myXamlString )
. 您可以将上面的xaml放入一个长字符串(以@"
开头,以在C#中使用多行字符串),然后调用XamlReader.Load( myXamlString )
。
Alternatively, you can create the hyperlink button and set its template in code-behind. 或者,您可以创建超链接按钮,并在隐藏代码中设置其模板。 Even in that case, however, the general advice is to use XamlReader to create the template from a string. 但是,即使在这种情况下,一般建议还是使用XamlReader从字符串创建模板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.