増加するパラメータに従って、内部を色で塗りつぶすコンテナを作成します。 メインウィンドウ:値に応じて高さを変更する
<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がDataContextのである例えば
iは、次の例を作成しました。それは素晴らしい作品ですが、私がやったよりもはるかに優れたものがあると思います。 さらに、ここではアニメーションが必要であることを意味する滑らかなものとしてChangeHeight()の転送が必要です。
良い例や指針はありますか?
UPDATE 私は、ビューモデルのコードを追加している:
namespace WpfApplication1
{ パブリッククラスのViewModel:m_height = 0 { プライベートint型をINotifyPropertyChangedの。 public int高さ { get {return m_height; } セット { 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
}
は}
ViewModelに 'INotifyPropertyChanged'を実装しましたか?そのコードを質問に追加できますか? – CKII
なぜあなたはそれが滑らかではないと感じますか?ここで何が起きてるの。詳細を追加できますか? – Versatile
参照:http://stackoverflow.com/questions/3762576/wpf-backgroundworker-vs-dispatcher – Versatile