简体   繁体   English

创建HyperlinkBut​​ton,并在其后的代码中包含文字换行(Windows Phone 8)

[英]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.

相关问题 Windows Phone-RichTextBox文字换行 - Windows Phone - RichTextBox text wrapping 将Windows Phone HyperlinkBut​​ton导航移植到Windows 8 HyperlinkBut​​ton导航 - Porting Windows Phone HyperlinkButton Navigation To Windows 8 HyperlinkButton Navigation 在Windows Phone 8.1后面的代码中创建新页面 - Create new page in code behind Windows Phone 8.1 无法将命令绑定到超链接按钮 (Windows Phone 8.1) - Unable to bind a Command to a HyperlinkButton (Windows Phone 8.1) 绑定HyperlinkBut​​ton Windows Phone 8的NavigateUri属性 - Bind NavigateUri property of HyperlinkButton Windows Phone 8 Windows Phone Dev 8更改HyperlinkBut​​ton图像(无SILVERLIGHT) - Windows Phone Dev 8 change HyperlinkButton Image (NO SILVERLIGHT) Windows Phone - 后面的代码中的ObjectAnimationUsingKeyFrames - Windows Phone - ObjectAnimationUsingKeyFrames in code behind Windows Phone的Silverlight中的文本包装问题 - Text Wrapping issue in silverlight for Windows Phone Windows Phone 8-StackPanel中的TextBlock无法正确包装文本吗? - Windows Phone 8 - TextBlock in StackPanel not wrapping Text properly? 如何使用HyperlinkBut​​ton在Windows Phone 8.1中显示ContentDialog页面 - How to use HyperlinkButton to show ContentDialog page in Windows Phone 8.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM