public override DataTemplate SelectTemplate(object item, DependencyObject container) { System.Windows.Window window = Application.Current.MainWindow; return(item != null && item is Category ? window.FindResource("ListItemsTemplate_Category") as DataTemplate : window.FindResource("ListItemsTemplate_Author") as DataTemplate); }
public void GetResourceObjectTest() { var window = new Window { Resources = { { "ViewModel", new ResourceObject { Properties = { new Property { PropertyName = "ResourceObject", Value = new Call { BuiltinFunction = BuiltinFunction.GetResourceObject }, } } } } } }; var viewModel = window.FindResource("ViewModel") as IDynamicObject; Assert.Equal(viewModel, viewModel["ResourceObject"]); }
public static void Show(System.Windows.Controls.UserControl WPFUserControl, string title, string sound, bool topmost, bool isModal) { GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); //Create window System.Windows.Window wnd = new System.Windows.Window(); wnd.Closing += new System.ComponentModel.CancelEventHandler(Window_Closing); wnd.Title = title; //Set window style try { wnd.Style = wnd.FindResource("StyleWindowMessage") as Style; } catch { //Set default style wnd.WindowStyle = WindowStyle.None; wnd.AllowsTransparency = true; wnd.Background = new SolidColorBrush(Colors.Transparent); wnd.ResizeMode = ResizeMode.NoResize; wnd.ShowInTaskbar = false; } object media = wnd.TryFindResource("media"); if(media != null && media is MediaElement) { MediaElement mediaElement = media as MediaElement; object showSound = wnd.TryFindResource("ShowWindowSound"); if(showSound != null && showSound is MediaTimeline) { mediaElement.LoadedBehavior = MediaState.Manual; mediaElement.UnloadedBehavior = MediaState.Manual; mediaElement.Source = new Uri("pack://application:,,,/SlideWindow;component/show.wav", UriKind.Absolute);//((MediaTimeline)showSound).Source; mediaElement.Volume = 5; mediaElement.Position = new TimeSpan(0); } mediaElement.Play(); } //Add WPFUserControl to window wnd.Content = WPFUserControl; //Set parameters wnd.Topmost = topmost; //Play sound after showing (set delay for sound) //Show window if(isModal) wnd.ShowDialog(); else wnd.Show(); wnd = null; GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); }
/// <summary> /// Updates the window constraints based on its state. /// For instance, the max width and height of the window is set to prevent overlapping over the taskbar. /// </summary> /// <param name="window">Window to set properties</param> private void UpdateWindowConstraints(Window window) { if (window != null) { // Make sure we don't bump the max width and height of the desktop when maximized var borderWidth = (GridLength) window.FindResource("BorderWidth"); window.MaxHeight = SystemParameters.WorkArea.Height + borderWidth.Value*2; window.MaxWidth = SystemParameters.WorkArea.Width + borderWidth.Value*2; } }
internal static void SlideToRight(Window parent, UserControl target) { var sb = parent.FindResource("SlideToRightAnimation") as Storyboard; Storyboard.SetTarget(sb, target); sb.Begin(); }