Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF MVVM how to create access key on run time
    text
    copied!<p>I can able to create <strong>access key</strong> for <strong><em>button content</em></strong> during Design time but unable to create during run time</p> <p><img src="https://i.stack.imgur.com/ZLPD6.png" alt="enter image description here"></p> <p>btnContent -- "C&amp;ancel" -- it works perfect</p> <p>btnContent -- "E&amp;xit" --- not working, when i try to give acces key for letter 'x'</p> <p>i have also tried with (_)underscore and "Exit" ,but no luck. i jus need to underline 'x' in string "Exit".</p> <p>Below is the style for my button</p> <pre><code> &lt;Style x:Key="LTC_ButtomForm_A" TargetType="{x:Type Button}"&gt; &lt;Style.Resources&gt; &lt;converter:ConverterFirstPartTextButton x:Key="ConverterFirstPartTextButton" /&gt; &lt;converter:ConverterUnderlineTextButton x:Key="ConverterUnderlineTextButton" /&gt; &lt;converter:ConverterLastPartTextButton x:Key="ConverterLastPartTextButton" /&gt; &lt;/Style.Resources&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type Button}"&gt; &lt;Border x:Name="Fondo" Margin="0" Padding="10,0" Background="#FF253A94" BorderBrush="#00000000" BorderThickness="1" CornerRadius="5"&gt; Text="{TemplateBinding Content,Converter={StaticResource ConverterFirstPartTextButton}}" TextAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Center"&gt; &lt;Run Text="{TemplateBinding Content, Converter={StaticResource ConverterUnderlineTextButton}}" TextDecorations="Underline" /&gt; &lt;Run Text="{TemplateBinding Content, Converter={StaticResource ConverterLastPartTextButton}}" /&gt; &lt;/TextBlock&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>where <strong>ConverterFirstPartTextButton</strong></p> <pre><code>Public Class ConverterFirstPartTextButton Implements IValueConverter #Region "IValueConverter Members" Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object _ Implements IValueConverter.Convert Dim part As String = String.Empty If value IsNot Nothing Then part = value.ToString().Split("&amp;").FirstOrDefault() End If Return part End Function Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) _ As Object Implements IValueConverter.ConvertBack Return value End Function #End Region End Class </code></pre> <p><strong>ConverterUnderlineTextButton</strong></p> <pre><code>Public Class ConverterUnderlineTextButton Implements IValueConverter #Region "IValueConverter Members" Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object _ Implements IValueConverter.Convert Dim underlineLetter As String = String.Empty If value IsNot Nothing Then underlineLetter = value.ToString().Split("&amp;").LastOrDefault End If If underlineLetter = value Then Return String.Empty Else underlineLetter = underlineLetter.Substring(0, 1) Return underlineLetter End If End Function Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) _ As Object Implements IValueConverter.ConvertBack Return value End Function #End Region End Class </code></pre> <p><strong>ConverterLastPartTextButton</strong></p> <pre><code>Public Class ConverterLastPartTextButton Implements IValueConverter #Region "IValueConverter Members" Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object _ Implements IValueConverter.Convert Dim part As String = String.Empty If value IsNot Nothing Then part = value.ToString().Split("&amp;").LastOrDefault End If If part &lt;&gt; value And part.Length &gt; 1 Then part = part.Substring(1) Return part Else Return String.Empty End If End Function Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) _ As Object Implements IValueConverter.ConvertBack Return value End Function #End Region End Class </code></pre> <p>these converts main use is to underline the given text and its working Perfect during initialization. But when i change the content during run time it shows as above image(fig 2). </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload