本文整理汇总了C#中System.Windows.Window.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Window.SetBinding方法的具体用法?C# Window.SetBinding怎么用?C# Window.SetBinding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Window
的用法示例。
在下文中一共展示了Window.SetBinding方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindingTopmost
public static void BindingTopmost(Window win)
{
Binding binding = new Binding("Topmost")
{
Source = MainFrame,
Mode = BindingMode.OneWay
};
win.SetBinding(Window.TopmostProperty, binding);
}
示例2: CreateWindowDoesNotSetUpTitleBindingIfTitleHasABindingAlready
public void CreateWindowDoesNotSetUpTitleBindingIfTitleHasABindingAlready()
{
var model = new Screen();
var window = new Window();
var binding = new Binding("Test") { Mode = BindingMode.TwoWay };
window.SetBinding(Window.TitleProperty, binding);
this.viewManager.Setup(x => x.CreateAndBindViewForModelIfNecessary(model)).Returns(window);
this.windowManager.CreateWindow(model, false);
var e = window.GetBindingExpression(Window.TitleProperty);
Assert.AreEqual("Test", e.ParentBinding.Path.Path);
}
示例3: DoSignInInUIThread
private Task<Credential> DoSignInInUIThread(CredentialRequestInfo credentialRequestInfo)
{
// Create the ChildWindow that contains the SignInDialog
var signInDialog = this;
var childWindow = new Window
{
ShowInTaskbar = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
WindowStyle = WindowStyle.ToolWindow,
SizeToContent = SizeToContent.WidthAndHeight,
ResizeMode = ResizeMode.NoResize,
WindowState = WindowState.Normal,
Content = signInDialog
};
if (Application.Current != null && Application.Current.MainWindow != null)
{
try
{
childWindow.Owner = Application.Current.MainWindow;
}
catch
{
// May fire an exception when used inside an excel or powerpoint addins
}
}
// Bind the Title so the ChildWindow Title is the SignInDialog title (that will be initialized later)
DependencyProperty titleProperty = Window.TitleProperty;
var binding = new Binding("Title") { Source = signInDialog };
childWindow.SetBinding(titleProperty, binding);
childWindow.Closed += (s, e) => signInDialog.Cancel(); // be sure the SignInDialog is deactivated when closing the childwindow using the X
// initialize the task that gets the credential and then close the window
var ts = TaskScheduler.FromCurrentSynchronizationContext();
var doSignInTask = signInDialog.WaitForCredentialAsync(credentialRequestInfo).ContinueWith(task =>
{
childWindow.Close();
return task.Result;
}, ts);
// Show the window
childWindow.ShowDialog();
return doSignInTask;
}
示例4: EnsureWindow
/// <summary>
/// Ensures the that the view is a window or provides one.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="view">The view.</param>
/// <param name="isDialog">Indicates we are insuring a dialog window.</param>
/// <returns></returns>
protected virtual Window EnsureWindow(object model, object view, bool isDialog)
{
var window = view as Window;
if (window == null)
{
window = new Window
{
Content = view,
SizeToContent = SizeToContent.WidthAndHeight
};
var screen = model as IPresenter;
if (screen != null)
{
var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay };
window.SetBinding(Window.TitleProperty, binding);
}
}
//else if (Application.Current != null && Application.Current.MainWindow != null)
//{
// if (Application.Current.MainWindow != window && isDialog)
// window.Owner = Application.Current.MainWindow;
//}
//if (Application.Current != null && Application.Current.MainWindow != null && Application.Current.MainWindow != window)
//{
// window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
// window.Owner = Application.Current.MainWindow;
//}
//else
// window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
//if (window.Style == null)
//{
// window.Style = Application.Current.TryFindResource(typeof(Window)) as Style;
//}
Window temp = null;
if (Application.Current != null)
foreach (Window item in Application.Current.Windows)
{
if (ReferenceEquals(window, item))
break;
temp = item;
}
window.WindowStartupLocation = temp == null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner;
window.Owner = temp;
return window;
}
示例5: DoSignInInUIThread
#pragma warning restore 1574
private static void DoSignInInUIThread(string url, Action<IdentityManager.Credential, Exception> callback, IdentityManager.GenerateTokenOptions generateTokenOptions
#if !SILVERLIGHT
, IdentityManager.AuthenticationType authenticationType = IdentityManager.AuthenticationType.Token
#endif
)
{
// In SL and WPF : Create the ChildWindow that contains the SignInDialog
#if SILVERLIGHT
ChildWindow childWindow = new ChildWindow();
DependencyProperty titleProperty = ChildWindow.TitleProperty;
#else
var childWindow = new Window
{
ShowInTaskbar = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
WindowStyle = WindowStyle.ToolWindow,
SizeToContent = SizeToContent.WidthAndHeight,
ResizeMode = ResizeMode.NoResize,
WindowState = WindowState.Normal
};
if (Application.Current != null && Application.Current.MainWindow != null)
{
try
{
childWindow.Owner = Application.Current.MainWindow;
}
catch (Exception)
{
// May fire an exception when used inside an excel or powerpoint addins
}
}
DependencyProperty titleProperty = Window.TitleProperty;
#endif
// Create the SignInDialog with the parameters given as arguments
var signInDialog = new SignInDialog
{
Url = url,
Callback = (credential, error) =>
{
childWindow.Close();
callback(credential, error);
},
GenerateTokenOptions = generateTokenOptions,
IsActive = true,
Width = 300,
#if !SILVERLIGHT
_authenticationType = authenticationType
#endif
};
childWindow.Content = signInDialog;
// Bind the Title so the ChildWindow Title is the SignInDialog title (taht will be initialized later)
Binding binding = new Binding("Title") { Source = signInDialog };
childWindow.SetBinding(titleProperty, binding);
childWindow.Closed += (s, e) => signInDialog.IsActive = false; // be sure the SignInDialog is deactivated (i.e. Callback executed once) when closing the childwindow using the X
// Show the window
#if SILVERLIGHT
childWindow.Show();
#else
childWindow.ShowDialog();
#endif
}
示例6: StartStandBildMappingControl
private void StartStandBildMappingControl (DataProfile profile,
CommonProfileModell.RequestedFunction FunctionToDo)
{
DataDependencyToWorkFor = profile.ActiveDataDependency;
DataDependencyCollectionToWorkFor = profile.DataDependencyCollectionToWorkForParameter;
if (StandBildMappingControlWindow != null)
StandBildMappingControlWindow.Close ();
if (StandBildMappingControlWindow == null)
{
StandBildMappingControlWindow = new Window ();
// StandBildMappingControlWindow.Title = CommonProfileModellInstance.HeadLineForProcessableStandBildMappingFull;
Binding TitleBinding = new Binding ()
{
Source = this,
Path = new PropertyPath ("CommonProfileModellInstance.HeadLineForProcessableStandBildMappingFull")
};
StandBildMappingControlWindow.SetBinding (Window.TitleProperty, TitleBinding);
StandBildMappingControl STBControl = new StandBildMappingControl ();
StandBildMappingControlWindow.Content = STBControl;
Binding ModellBinding = new Binding ("CommonProfileModellInstance")
{Source = this};
STBControl.SetBinding (StandBildMappingControl.CommonProfileModellInstanceProperty, ModellBinding);
Binding FullDataDependencyToWorkForBinding = new Binding("FullDataDependencyToWorkFor")
{ Source = this };
STBControl.SetBinding(StandBildMappingControl.DataDependencyToWorkForProperty,
FullDataDependencyToWorkForBinding);
Binding FullDataDependencyCollectionToWorkForBinding = new Binding("FullDataDependencyCollectionToWorkFor")
{ Source = this };
STBControl.SetBinding(StandBildMappingControl.FullDataDependencyCollectionToWorkForProperty,
FullDataDependencyCollectionToWorkForBinding);
StandBildMappingControlWindow.Closing += (O, Args) =>
{
STBControl.CloseRequested ();
StandBildMappingControlWindow = null;
};
switch (FunctionToDo)
{
case CommonProfileModell.RequestedFunction.Show:
STBControl.IsReadOnly = true;
break;
case CommonProfileModell.RequestedFunction.New:
case CommonProfileModell.RequestedFunction.Modify:
case CommonProfileModell.RequestedFunction.Delete:
STBControl.IsReadOnly = false;
break;
}
}
//((CommonProfileModell) CommonProfileModellInstance).FunctionToDo = FunctionToDo;
//((CommonProfileModell) CommonProfileModellInstance).SelectedDataTemplatesDescription = ActiveFullDataDependency;
//((CommonProfileModell) CommonProfileModellInstance).DoRequestedFunction ();
StandBildMappingControlWindow.Show ();
}
示例7: OpenTopLevelView
/// <summary>
/// Opens the top level view in a separate window.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="messageBoxResult">The message box result.</param>
/// <param name="viewResult">The view result.</param>
/// <returns>True if successfully opened</returns>
private bool OpenTopLevelView(RequestContext context, MessageBoxResult messageBoxResult, ViewResult viewResult)
{
if (messageBoxResult != null && string.IsNullOrEmpty(viewResult.ViewIconResourceKey))
viewResult.ViewIconResourceKey = messageBoxResult.ModelMessageBox.IconResourceKey;
//Brush iconBrush = Brushes.Transparent;
//if (!string.IsNullOrEmpty(viewResult.ViewIconResourceKey))
// try
// {
// var resource = Application.Current.FindResource(viewResult.ViewIconResourceKey);
// if (resource != null)
// iconBrush = (Brush) resource;
// }
// catch
// {
// iconBrush = Brushes.Transparent;
// }
// If we respect local views and the view is in fact a local view, and we have a normal view already open, then we open it in a local way only.
if (viewResult.ViewScope == ViewScope.Local && HandleLocalViewsSpecial && SelectedNormalView > -1)
{
var selectedView = NormalViews[SelectedNormalView];
if (selectedView == null) return false;
selectedView.LocalViews.Add(viewResult);
if (viewResult.MakeViewVisibleOnLaunch)
selectedView.SelectedLocalViewIndex = selectedView.LocalViews.Count - 1;
return true;
}
//Need to make sure we do not open more than allowed - Popups should not close underlying views.
if (viewResult.ViewLevel != ViewLevel.Popup && MaximumTopLevelViewCount > -1)
{
var inplaceTopLevelviews = TopLevelViews.Where(v => v.TopLevelWindow == null).ToList();
while (inplaceTopLevelviews.Count + 1 > MaximumTopLevelViewCount)
{
CloseViewForModel(inplaceTopLevelviews[0].Model);
inplaceTopLevelviews.RemoveAt(0);
}
}
TopLevelViews.Add(viewResult);
if (viewResult.MakeViewVisibleOnLaunch && !(TopLevelViewLaunchMode == ViewLaunchMode.Popup || (TopLevelViewLaunchMode == ViewLaunchMode.InPlaceExceptPopups && viewResult.ViewLevel == ViewLevel.Popup)))
{
SelectedTopLevelView = TopLevelViews.Count - 1;
SelectedTopLevelViewResult = SelectedTopLevelView > -1 ? TopLevelViews[SelectedTopLevelView] : null;
if (viewResult.View != null)
if (!FocusHelper.FocusFirstControlDelayed(viewResult.View))
FocusHelper.FocusDelayed(viewResult.View);
}
TopLevelViewCount = TopLevelViews.Count;
if (TopLevelViewLaunchMode == ViewLaunchMode.Popup || (TopLevelViewLaunchMode == ViewLaunchMode.InPlaceExceptPopups && viewResult.ViewLevel == ViewLevel.Popup))
{
var window = new Window
{
Title = viewResult.ViewTitle,
Content = viewResult.View,
DataContext = viewResult.Model,
WindowStartupLocation = WindowStartupLocation.CenterScreen,
Owner = this
};
window.SetBinding(TitleProperty, new Binding("ViewTitle") { Source = viewResult });
// Setting the size strategy
var strategy = SimpleView.GetSizeStrategy(viewResult.View);
switch (strategy)
{
case ViewSizeStrategies.UseMinimumSizeRequired:
window.SizeToContent = SizeToContent.WidthAndHeight;
break;
case ViewSizeStrategies.UseMaximumSizeAvailable:
window.SizeToContent = SizeToContent.Manual;
window.Height = SystemParameters.WorkArea.Height;
window.Width = SystemParameters.WorkArea.Width;
break;
case ViewSizeStrategies.UseSuggestedSize:
window.SizeToContent = SizeToContent.Manual;
window.Height = SimpleView.GetSuggestedHeight(viewResult.View);
window.Width = SimpleView.GetSuggestedWidth(viewResult.View);
break;
}
viewResult.TopLevelWindow = window;
if (context.Result is MessageBoxResult) window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-TopLevelMessageBoxWindowStyle");
else window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-TopLevelWindowStyle");
if (viewResult.View != null)
foreach (InputBinding binding in viewResult.View.InputBindings)
window.InputBindings.Add(binding);
//.........这里部分代码省略.........
示例8: OpenNormalViewInWindow
/// <summary>
/// Opens a normal view in a separate window.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="viewResult">The view result.</param>
private static void OpenNormalViewInWindow(RequestContext context, ViewResult viewResult)
{
var window = new Window
{
Title = viewResult.ViewTitle,
SizeToContent = SizeToContent.WidthAndHeight,
Content = viewResult.View,
DataContext = viewResult.Model,
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
window.SetBinding(TitleProperty, new Binding("ViewTitle") {Source = viewResult});
var simpleView = viewResult.View as SimpleView;
if (simpleView != null)
if (SimpleView.GetSizeStrategy(simpleView) == ViewSizeStrategies.UseMaximumSizeAvailable)
window.SizeToContent = SizeToContent.Manual;
viewResult.TopLevelWindow = window;
if (context.Result is MessageBoxResult) window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-TopLevelMessageBoxWindowStyle");
else window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-NormalLevelWindowStyle");
if (viewResult.IsModal) window.ShowDialog();
else window.Show();
}