Hi,
I think, your ProxyElement doesn't detect PropertyChanged. My demo works fine, try it.
XAML:
<Window x:Class="WpfApp1.Window074"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp074"
mc:Ignorable="d"
Title="Window074" Height="450" Width="800">
<Window.Resources>
<local:ViewModel x:Key="vm"/>
<local:MyMultiValueConverter x:Key="MyMultiValueConverter"/>
</Window.Resources>
<StackPanel DataContext="{StaticResource vm}">
<TextBox Text="{Binding WidthValue}"/>
<CheckBox IsChecked="{Binding WidthDefault}" Content="Default Width"/>
<DataGrid ItemsSource="{Binding View}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Col1" Binding="{Binding SomeString}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Width">
<Setter.Value>
<MultiBinding Converter="{StaticResource MyMultiValueConverter}">
<Binding Path="WidthValue" Source="{StaticResource vm}"/>
<Binding Path="WidthDefault" Source="{StaticResource vm}"/>
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</Window>
Code:
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Data;
namespace WpfApp074
{
public class ViewModel : INotifyPropertyChanged
{
public ViewModel()
{
ObservableCollection<Data> col = new ObservableCollection<Data>();
for (int i = 1; i < 10; i++) col.Add(new Data() { SomeString = $"Row {i}" });
cvs.Source = col;
}
private CollectionViewSource cvs = new CollectionViewSource();
public ICollectionView View { get => cvs.View; }
private double _widthValue = 20;
public double WidthValue
{
get => this._widthValue;
set { this._widthValue = value; OnPorpertyChanged(); }
}
private bool _widthDefault = false;
public bool WidthDefault
{
get => this._widthDefault;
set { this._widthDefault = value; OnPorpertyChanged(); }
}
public event PropertyChangedEventHandler PropertyChanged;
internal void OnPorpertyChanged([CallerMemberName] string propName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
public class Data
{
public string SomeString { get; set; }
}
public class MyMultiValueConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
double w = 100;
if (!(bool)values[1]) double.TryParse(values[0].ToString(), out w);
return w;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}