chustar
chustar

Reputation: 12465

Items hidden when added to HyperLinkButton

The items below show up normally when I do not have them inside the HyperlinkButton.
However, when I add them to the HyperlinkButton, they become invisible.

<DataTemplate>
    <HyperlinkButton NavigateUri="/ViewChallenge.aspx">
        <HyperlinkButton.Content>
            <StackPanel Orientation="Horizontal" Margin="0,0,0,17">
                <Image Height="100" Width="100" Source="{Binding Path=Challenge.Image}" Margin="12,0,9,0"/>
                <StackPanel Width="311">
                    <TextBlock Text="{Binding Path=Challenge.Title}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                    <HyperlinkButton NavigateUri="ViewUser.aspx" >
                        <HyperlinkButton.Content>
                            <TextBlock Text="{Binding Path=User.Username}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                        </HyperlinkButton.Content>
                    </HyperlinkButton>
                 </StackPanel>
             </StackPanel>
        </HyperlinkButton.Content>
    </HyperlinkButton>
</DataTemplate>

Upvotes: 1

Views: 351

Answers (1)

Edward
Edward

Reputation: 7424

As far as I know, the Hyperlink button only supports text. For example:

<HyperlinkButton Height="100" Width="300">
    Hello World
</HyperlinkButton>

Maybe you should use a Button control and set a Control template and enter the XAML you mentioned above inside. It makes more sense in my opinion. Try this:

<ControlTemplate x:Key="MyButtonTemplate" TargetType="Button">
         <StackPanel Orientation="Horizontal" Margin="0,0,0,17">      
            <Image Height="100" Width="100" Source="{Binding Path=Challenge.Image}" Margin="12,0,9,0"/>      
            <StackPanel Width="311">      
                <TextBlock Text="{Binding Path=Challenge.Title}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>          
                <TextBlock Text="{Binding Path=User.Username}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>      
             </StackPanel>      
         </StackPanel>   
</ControlTemplate>

And simply set the template for your button like so:

<Button x:Name="myButton" Template="{StaticResource MyButtonTemplate}" Click="myButton_Click"/>

And then do the navigation inside the click event.

Upvotes: 2

Related Questions