I want to change something in the UI side after a button click. Let's say changing button width after clicking the button.
<Button x:Name="btnButt" Content="Button"/>
Then in my ViewModel,
View.MyDialog mydialog = new View.MyDialog();
mydialog.btnButt.Width = 3000;
However, everything is not working. I also tried binding a string from the ViewModel:
\\ XAML
<Button x:Name="btnButt" Content="Button" Width="{Binding WidthVM}"/>
\\ ViewModel
public int WidthVM = 3000;
What could be missing?
I will not recommend your first solution because it would kill the purpose of MVVM.
Your second solution is actually correct which is to bind some data from the VM. It did not work because you need to have it in MVVM way to send signal changes to the UI, have it like this:
public const string WidthVMPropertyName = "WidthVM";
private int _widthVM = 0;
public int WidthVM
{
get
{
return _widthVM;
}
set
{
Set(WidthVMPropertyName, ref _widthVM, value);
}
}
\\ then set it like:
WidthVM = 3000;