Silverlight - 防止 ChildWindow 移动

发布于 2024-08-30 01:47:01 字数 67 浏览 2 评论 0 原文

有人有任何巧妙的解决方案来防止 Silverlight ChildWindow 被移动吗?

谢谢, 标记

Anyone got any neat solutions to prevent a Silverlight ChildWindow being moved?

thanks,
Mark

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

じее 2024-09-06 01:47:01

我不确定您是否会认为这很简洁,但是...

  • 为自己创建一个新的模板化控件并将其命名为 ImmovableChildWindow
  • 修改其继承的类为ChildWindow
  • 打开 Themes/generic.xaml,您将找到 ImmoveableChildWindow 的初始样式。
  • 在 Silverlight 文档中,您将在 ChildWindow 样式和模板
  • 请注意 ImmovableChildWindow 样式的现有 TargetType 值。
  • 将文档中的 ChildWindow 的整个默认样式复制并粘贴到您的主题/generic.xaml 文件中。
  • 将此副本的 TargetType 替换为与现有 ImmovaleChildWindow 样式相同的值。
  • 您现在可以删除初始样式。现在只保留针对 ImmovableChildWindow 的 ChildWindow 样式的大副本。
  • Template setter 中查找,将 TargetType 更改为与样式 TargetType 相同的值
  • 搜索模板并找到 Border< /code> 名称为 Chrome。删除 x:Name="Chrome" 属性。 (这才是我们真正追求的)。

现在,当您创建一个新的 ChildWindow 项目时,它将默认继承 ChildWindow 形式,如果您希望它不可移动,则需要修改它以继承 ImmovableChildWindow (更改基类)在 xaml 中输入代码隐藏和根标记名称)。

ChildWindow 将事件附加到名称为“Chrome”的 FrameWorkElement,从而使子窗口能够移动。然而,作为一个行为良好的模板化控件,如果它找不到名为“Chrome”的 FrameworkElement,它就会在没有该功能的情况下继续工作。

I'm not sure you'd call this neat but...

  • Create yourself a new Templated control and call it ImmovableChildWindow.
  • Modify the class it inherits from to be ChildWindow.
  • Open Themes/generic.xaml you will find an initial style for the ImmoveableChildWindow
  • In the Silverlight documentation you'll find the existing template for a ChildWindow at ChildWindow Styles and Templates.
  • Note the existing TargetType value for the ImmovableChildWindow style.
  • Copy'n' paste the whole default style for a ChildWindow from the documentation into your themes/generic.xaml file.
  • Replace TargetType for this copy to the same value as the exiting ImmovaleChildWindow style.
  • You can now delete the initial style. Leave only the large copy of ChildWindow style now targeting ImmovableChildWindow.
  • Find within the Template setter change the TargetType of to the same value as the style TargetType
  • Search through the template and find a Border with the name Chrome. Delete the x:Name="Chrome" attribute. (This is what we are really after).

Now when you create a new ChildWindow item it will by default inherit form ChildWindow, if you want it to be immovable you need modify it to inherit from ImmovableChildWindow instead (change the base type in the code-behind and the root tag name in the xaml).

The ChildWindow attaches events to the FrameWorkElement with the name "Chrome" which enables the child window to be moved about. However being a well-behaved templated control, if it can't find a FrameworkElement called "Chrome" it just continues to work without that feature.

反话 2024-09-06 01:47:01

不需要创建新类,而是

  1. 从以下位置复制样式:http://msdn.microsoft.com/en-us/library/dd833070%28VS.95%29.aspx

  2. 给出x:key="stylename"

  3. Childwindow 的构造函数中,在 InitializeComponent 之前粘贴以下代码:

    this.Style = App.Current.Resources["childWindow"] 作为样式;

上面解决方案解决了我的问题

Not Required to Create new class, instead

  1. Copy the style from: http://msdn.microsoft.com/en-us/library/dd833070%28VS.95%29.aspx

  2. Give x:key="stylename"

  3. In Construtor of Childwindow, paste following code before InitializeComponent:

    this.Style = App.Current.Resources["childWindow"] as Style;

above solution resolved my issue

你曾走过我的故事 2024-09-06 01:47:01

也许你可以尝试这个简单的方法来做到这一点:
创建一个网格来扭曲 ChildWindow 中的所有内容。

<Grid Margin="0">

<!--Your ChildWindow. Canvas, Grid, Textblock...Whatever-->

</Grid>

由于网格的边距为 0,因此您无法单击它并移动它。

Maybe you can try this simple way to do that:
Create a Grid to warp all the content in your ChildWindow.

<Grid Margin="0">

<!--Your ChildWindow. Canvas, Grid, Textblock...Whatever-->

</Grid>

Since the Grid has a 0 margin, you can not click it and move it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文