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>

20 Şubat 2010 Cumartesi

WPF Inheritance

2 adet wpf windowumuz var Birinin adı WindowBase.cs olsun diğeri Window1.cs olsun

Window1 WindowBase'i miras alsın yapı aşağıdaki gibidir:

XAML:

WpfApplication1:WindowBase


CodeBehind:

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


Bu şekil yazdıktan sonra geriye önemli bi nokta daha kalıyor. Görüntüde inherit olayı tamam ama hata verir. Hatalar şöyle :

Warning 1 'WpfApplication1.Window1.InitializeComponent()' hides inherited member 'WpfApplication1.WindowBase.InitializeComponent()'. Use the new keyword if hiding was intended. C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WpfApplication1\WpfApplication1\obj\Debug\Window1.g.cs 48 21 WpfApplication1

Error 2 'WpfApplication1.WindowBase' cannot be the root of a XAML file because it was defined using XAML. Line 1 Position 29. C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WpfApplication1\WpfApplication1\Window1.xaml 1 29 WpfApplication1


İnherit işlemini tamamlamak için WindowBase windowunun property penceresinde BuildAction propertysini Resource seçmek yeterlidir

derleme işleminde inherit olayının hatasız tamamlandığı görülecektir. İyi çalışmalar.