How to install packaging for HyperlinkButton with content / text with database binding?

I bind the collection (rss channel) to the list box, for example:

<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Margin="0,0,0,17" Width="432"> <HyperlinkButton Content={Binding Title} NavigateUri="{Binding Link}" /> <TextBlock Text="{Binding Description}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> 

This works great - data is displayed correctly, etc. But now that I have changed it to use text wrapping, the title no longer displays.

Here is the problematic code.

 <ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Margin="0,0,0,17" Width="432"> <HyperlinkButton NavigateUri="{Binding Link}"> <TextBlock Text="{Binding Title}" TextWrapping="Wrap" /> </HyperlinkButton> <TextBlock Text="{Binding Description}" TextWrapping="Wrap" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> 

I don’t think this is the “TextWrapping” attribute, which is causing the problem since I tried without it and it still didn't work. So my question is: how do you work on this? I just want to display a hyperlink with wrapped related text. It seems like a pretty simple thing - but still so complicated. Help?

+6
data-binding hyperlink silverlight
source share
2 answers

I had the same problem, and I could not understand why it did not work until I came across this blog a href = "http://www.pitorque.de/MisterGoodcat/author/Mister-Goodcat.aspx "rel =" noreferrer "> Mr. Goodcat. In his post, he said that due to some optimization made for WP7 in Silverlight, the basic functionality that works in regular Silverlight does not work correctly for WP7 Silverlight. Instead of using it, he suggests changing the style instead.

The easiest way to edit default templates is to use Expression Blend to make a copy and work from there. When you do this, you will see that the template really only has a text block to display the content. This is why using a different user interface element as content does not work for the hyperlink button on WP7. If you only want to do text wrapping, just change the TextWrapping property in this text block.

 <Style x:Key="HyperlinkButtonWrappingStyle" TargetType="HyperlinkButton"> <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}" /> <Setter Property="Background" Value="Transparent" /> <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}" /> <Setter Property="Padding" Value="0" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="HyperlinkButton"> <Border Background="Transparent"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal" /> <VisualState x:Name="MouseOver" /> <VisualState x:Name="Pressed"> <Storyboard> <DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="TextElement" /> </Storyboard> </VisualState> <VisualState x:Name="Disabled"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="TextElement"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border Background="{TemplateBinding Background}" Margin="{StaticResource PhoneHorizontalMargin}" Padding="{TemplateBinding Padding}"> <TextBlock x:Name="TextElement" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Text="{TemplateBinding Content}" TextDecorations="Underline" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" TextWrapping="Wrap" /> </Border> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> 

I suggest reading his blog post for more information and help.

+7
source share

Here's a solution to the problem: http://www.pitorque.de/MisterGoodcat/post/WP7-snippet-analyzing-the-hyperlink-button-style.aspx#continue

The code above works fine in SL4, but not in Windows Phone 7; mainly for performance reasons. Use Blend to edit the HyperlinkButton style, where you find that Hyperlinkbutton already uses a TextBlock to display content and adds the TextWrapping = "Wrap" property.

+1
source share

All Articles