Sayfalar

12 Mart 2010 Cuma

DispatcherTimer Kullanmak

WPF uygulamasında timer kullanmak icab ederse DispatcherTimer() kullanmak en uygunu. Thread’ler ile uğraşmaya gerek kalmadan ihtiyacımız karşılanıyor. Bir örnek verelim.

using System.Windows.Threading;

public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}

private DispatcherTimer _timer;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromMilliseconds(100);
_timer.Tick += new EventHandler(_timer_Tick);
_timer.Start();
}

void _timer_Tick(object sender, EventArgs e)
{
//StatusBatItem Contentine değer verilir
sbItem1.Content = DateTime.Now.Second;
}
}

2 Mart 2010 Salı

The property 'Resources' is set more than once. Hatası ve Çözümü

Yanlış:

<HbysWpf:WindowBase.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\Resources\Chart2d\RoyaleVelvet\Chart2D.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<Button x:Key="ButtonDataSource"/>
</HbysWpf:WindowBase.Resources>

Doğru:

<HbysWpf:WindowBase.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\Resources\Chart2d\RoyaleVelvet\Chart2D.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Button x:Key="ButtonDataSource"/>
</ResourceDictionary>
</HbysWpf:WindowBase.Resources>