I want to create a container that fills the inside with a color according to a parameter that increases.
for example i created the following example: MainWindow:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Border BorderBrush="Black" BorderThickness="1" Width="100" Height="200">
<Rectangle VerticalAlignment="Bottom" Height="{Binding Height}" Width="100" Fill="Red" MaxHeight="200"/>
</Border>
</Grid>
Engine.cs:
class Engine
{
public ViewModel viewModel = new ViewModel();
public void process()
{
Thread a = new Thread(() =>
{
while (viewModel.Height < 200)
{
ChangeHeight();
Thread.Sleep(1000);
}
});
a.IsBackground = true;
a.Start();
}
public void ChangeHeight()
{
viewModel.Height++;
}
}
ViewModel is the datacontext. It works great but I think there's something much better than what i did. Moreover, I need the transfer bewtween ChangeHeight() to be smooth meaning an animation is required here.
Is there any good example or guidance?
UPDATE I'm adding the view model code:
namespace WpfApplication1
{ public class ViewModel : INotifyPropertyChanged { private int m_height = 0; public int Height { get { return m_height; } set { m_height = value; NotifyPropertyChanged("Height"); } }
#region "PropertyChanged Event"
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}
INotifyPropertyChanged
in the ViewModel? Can you add its code to the question? – CKII