4
votes

I have a button that has its content (text) set dynamically via a style against a backing property as below.

<Button>
   <Button.Style>
      <Style>
         <Setter Property="Button.Content" Value="Advanced Search" />
         <Style.Triggers>
            <DataTrigger Binding="{Binding Path=IsAdvancedSearch}" Value="True">
               <Setter Property="Button.Content" Value="Standard Search" />
            </DataTrigger>
         </Style.Triggers>
      </Style>
   </Button.Style>
</Button>

I need to change this button to display just a hyperlink with the same dynamic text. Like this:

<Button>
   <Button.Template>
      <ControlTemplate>
         <TextBlock>
            <Hyperlink>
               Standard Search
            </Hyperlink>
         </TextBlock>
      </ControlTemplate>
   </Button.Template>
</Button>

Is there a way to set the hyperlink's text (inline or some other tag) dynamically via a style still?

I haven't been able to get access to it via XAML. I got it working with a normal binding on a textblock inside the hyperlink but that is creating a redundant property on the viewmodel really.

4

4 Answers

8
votes

You can embed another TextBlock inside your Hyperlink and bind it:

<TextBlock>
    <Hyperlink>
        <TextBlock Text="{Binding LinkText}" />
    </Hyperlink>
</TextBlock>
4
votes

Solution was to simply apply the style to an inner Textblock.

            <Button x:Name="SwitchSearchType">
                <Button.Template>
                    <ControlTemplate>
                        <TextBlock>
                            <Hyperlink>
                                <Hyperlink.Inlines>
                                    <TextBlock>
                                        <TextBlock.Style>
                                            <Style>
                                                <Setter Property="TextBlock.Text" Value="Advanced Search" />
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding Path=IsAdvancedSearch}" Value="True">
                                                        <Setter Property="TextBlock.Text" Value="Standard Search" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </TextBlock.Style>
                                    </TextBlock>
                                </Hyperlink.Inlines>
                            </Hyperlink>
                        </TextBlock>
                    </ControlTemplate>
                </Button.Template>
            </Button>
0
votes
 <GridViewColumn Header="{x:Static lang:Lang.wName}"  CellTemplate="{StaticResource Template_DebitAccount}" />

And use into skin file 

<DataTemplate x:Key="Template_DebitAccount">
    <Border Padding="3" >
        <TextBlock Text="{Binding wDebitAccountName}" Style="{StaticResource TextStyle_Path}">
            <TextBlock.InputBindings>
                <MouseBinding MouseAction="LeftClick" Command="{Binding DataContext.Base_PopPageCommand , RelativeSource={RelativeSource AncestorType=ListView}}" >
                    <MouseBinding.CommandParameter>
                        <MultiBinding Converter="{StaticResource MultiValueBindingConverter}">
                            <Binding Source="AgentSummary" />
                            <Binding Path="Link_Text"/>
                        </MultiBinding>
                    </MouseBinding.CommandParameter>
                </MouseBinding>
            </TextBlock.InputBindings>
        </TextBlock>
    </Border>
</DataTemplate>
-2
votes

Given:

<Hyperlink x:Name="uriEmailAddress" Click="Hyperlink_Click"></Hyperlink>

Code:

string e = Properties.Settings.Default.Email;
uriEmailAddress.NavigateUri = new Uri("mailto:" + e);
InlineCollection ic = uriEmailAddress.Inlines;
ic.Add(new Run(e));