I have a WPF application where I need to show a rectangle at the top of the title bar. But the Rectangle should not cover the whole title bar. For this purpose I use a IValueConverter which gives me the exact output which I want. I do a data binding with the width of that Rectangle and use the converter there.
My problem is I need to use another Rectangle on that title bar but I except different value from that converter. Because this time Rectangle size is very small. Some people suggest me to use converter parameter. I use that but I don't get any value from it.
Here is my IValueConverter in C# :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Globalization;
namespace WpfApp1
{
public class WpConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return double.Parse(value.ToString()) - 142;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Here is the Xaml code of my Rectangle:
<Rectangle Fill="Yellow" Stroke="{x:Null}" Grid.Row="0" HorizontalAlignment="Stretch" Width="{Binding Path=ActualWidth, ElementName=xp, Converter={StaticResource WpConverter}}" VerticalAlignment="Top" Height="1" Margin="-140,0,0,0" x:Name="top" PreviewMouseDown="Resize" MouseMove="DisplayResizeCursor" />
I need to use another similar Rectangle But If I use the same converter I get the same values. The main goal is to change this line return
double.Parse(value.ToString()) - 142;
the another way I found is to declare another IValueConverter with different values. But that pretty awkward. I need to do something using converter parameter.