A Microsoft platform for building and publishing apps for Windows devices.
Hi,
excuse me, here is another approach for UWP.
<Page
x:Class="App1.Page15"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App15"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel>
<StackPanel.Resources>
<local:MySubstringConverter x:Key="Substring" ConverterParameter="{Binding Tag, ElementName=txtMessageOut}" />
</StackPanel.Resources>
<TextBox x:Name="txtMessage"/>
<TextBox x:Name="txtMessageOut" Tag="end"/>
<TextBlock Text="{Binding Text, ElementName=txtMessage, Converter={StaticResource Substring}}"/>
</StackPanel>
</Page>
And converter:
public class MySubstringConverter : DependencyObject, IValueConverter
{
public static readonly DependencyProperty ConverterParameterProperty =
DependencyProperty.RegisterAttached("ConverterParameter", typeof(string),
typeof(MySubstringConverter), new PropertyMetadata(string.Empty));
public static string GetConverterParameter(DependencyObject obj) => obj.GetValue(ConverterParameterProperty) as string;
public static void SetConverterParameter(DependencyObject obj, string value) => obj.SetValue(ConverterParameterProperty, value);
public object ConverterParameter
{
get { return GetValue(ConverterParameterProperty); }
set { SetValue(ConverterParameterProperty, value); }
}
public object Convert(object value, Type targetType, object parameter, string language)
{
// Converter functionality
return (value ?? "").ToString() + " - " + (this.ConverterParameter ?? "").ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
Result: