本文整理汇总了C#中System.Windows.Window.FindResource方法的典型用法代码示例。如果您正苦于以下问题:C# Window.FindResource方法的具体用法?C# Window.FindResource怎么用?C# Window.FindResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Window
的用法示例。
在下文中一共展示了Window.FindResource方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetResourceObjectTest
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"]);
}
示例2: Show
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);
}
示例3: UpdateWindowConstraints
/// <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;
}
}
示例4: SlideToRight
internal static void SlideToRight(Window parent, UserControl target)
{
var sb = parent.FindResource("SlideToRightAnimation") as Storyboard;
Storyboard.SetTarget(sb, target);
sb.Begin();
}