CommandManager.InvalidateRequerySuggested();
を実行して、RequerySuggestedイベントを強制的に発生させてCanExecuteが実行されるようにできる。
UIスレッドと別スレッドから呼び出すときはDispatcher.Invoke()やDispatcher.BeginInvokeのデリゲートから呼び出す。
CommandManager.InvalidateRequerySuggested();
を実行して、RequerySuggestedイベントを強制的に発生させてCanExecuteが実行されるようにできる。
UIスレッドと別スレッドから呼び出すときはDispatcher.Invoke()やDispatcher.BeginInvokeのデリゲートから呼び出す。
WPFでWindows FormのApplication.DoEventsメソッドと同様に長時間かかる処理の間にUIのイベントを処理させるには、下記のように行う。(MSDNより)
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public void DoEvents()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
new DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}public object ExitFrame(object f)
{
((DispatcherFrame)f).Continue = false;return null;
}
WPF.Themesを使ってWPFでSilverlight ToolkitのようなThemeを使用することができる。現状21種類のテーマが提供されている。
<Window x:Class=”WpfApplication1.Window1″
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:themes=”clr-namespace:WPF.Themes;assembly=WPF.Themes”
themes:ThemeManager.Theme=”ShinyRed”
Title=”Window1″ Height=”300″ Width=”300″>
.Net framework 3.5 SP1からWPFにもWebBrowserコントロールが追加された。
WebBrowserコントロールのDocumentプロパティは型objectとなっているが、COM参照「Microsoft Html Object Library」を追加すると、mshtml.HTMLDocumentにキャスト可能となり、HTMLドキュメントの操作等が可能となる。
Page(Window)ロード時にスクロールなしの状態のコントロールの座標を取得しておく。
scrollY = targetControl.TranslatePoint(new Point(0, 0), scrollviewer1).Y;
下記を実行してスクロールを行う。
scrollviewer1.ScrollToVerticalOffset(scrollY );
PreviewLostKeyboardFocusイベントでKeyboardFocusChangedEventArgsのHandledプロパティをtrueにする。
ButtonのCommandプロパティをセットする。下記は組み込みのApplicationCommands.Saveを使用する場合。
<Button Height=”23″ Name=”button1″ Width=”75″ Command=”ApplicationCommands.Save”>Button</Button>
Xamlのコードビハインドクラスのコンストラクタで、commandBindingを作成し、ExecutedイベントとCanExecuteイベントを登録し、CommandBindingsプロパティにcommandBindingを追加する。
CommandBinding binding = new CommandBinding(ApplicationCommands.Save);
binding.Executed += new ExecutedRoutedEventHandler(executeMethod);
binding.CanExecute += new CanExecuteRoutedEventHandler(binding_CanExecute);
this.CommandBindings.Add(binding);
Executedイベントはコマンドでするべき処理を実行する。CanExecuteイベントはコントロールがコマンドを実行できるかどうか確認するときに呼び出す。コマンドが実行できる状態の場合は、
void binding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
のようにパラメータのCanExecuteプロパティにtrueをセットする。