我正在编写一个自定义控件,我希望控件在用户点击控件时从编辑状态切换到正常状态.我正在处理LostFocus事件,这有助于当用户选中时或者他们点击另一个可聚焦的控件时.但如果他们没有点击Focusable,它就不会切换出它的编辑状态.所以我有两个解决方案:
MouseDownEvent(并处理"已处理"事件)时,将树向上移动到最顶层元素.在处理程序中,我将控件从其编辑状态中踢出,并从最顶层的元素中删除处理程序.这看起来有点像黑客,但它可能会运作良好.示例代码:
private void RegisterTopMostParentMouseClickEvent()
{
_topMostParent = this.FindLastVisualAncestor<FrameworkElement>();
if ( _topMostParent == null )
return;
_topMostParent.AddHandler( Mouse.MouseDownEvent, new MouseButtonEventHandler( CustomControlMouseDownEvent ), true );
}
private void UnRegisterTopMostParentMouseClickEvent()
{
if ( _topMostParent == null )
return;
_topMostParent.RemoveHandler( Mouse.MouseDownEvent, new MouseButtonEventHandler( CustomControlMouseDownEvent ) );
_topMostParent = null;
}
Run Code Online (Sandbox Code Playgroud)
Mouse.PreviewMouseDownOutsideCapturedElement并向我的控件添加处理程序.在处理程序中,我将控件从其编辑状态中踢出.但我似乎没有让事件发生.Mouse.PreviewMouseDownOutsideCapturedElement什么时候开始?示例代码:
AddHandler( Mouse.PreviewMouseDownOutsideCapturedElementEvent, new MouseButtonEventHandler( EditableTextBlockPreviewMouseDownOutsideCapturedElementEvent ), true );
Run Code Online (Sandbox Code Playgroud) 我正在写一个Windows 8 Metro应用程序.我正在尝试使用三个组绘制GridView.我希望其中一个组以不同于其他组的方式布置项目.我之前在WPF中使用过选择器,所以我认为这是一条好路线.所以我尝试了GroupStyleSelector,我在MSDN上找到了这个例子:
public class ListGroupStyleSelector : GroupStyleSelector
{
protected override GroupStyle SelectGroupStyleCore(object group, uint level)
{
return (GroupStyle)App.Current.Resources["listViewGroupStyle"];
}
}
Run Code Online (Sandbox Code Playgroud)
所以我改编/扩展了适合我的东西:
CS:
public class ExampleListGroupStyleSelector : GroupStyleSelector
{
public ExampleListGroupStyleSelector ()
{
OneBigItemGroupStyle = null;
NormalGroupStyle = null;
}
public GroupStyle OneBigItemGroupStyle { get; set; }
public GroupStyle NormalGroupStyle { get; set; }
protected override GroupStyle SelectGroupStyleCore( object group, uint level )
{
// a method that tries to grab an enum off the bound …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的Ubuntu VPS上托管一个Django应用程序.我安装了python,django和女服务员,目录移了过来.
我去了女服务员网站(http://docs.pylonsproject.org/projects/waitress/en/latest/)他们说要像这样使用它:
from waitress import serve
serve(wsgiapp, host='5.5.5.5', port=8080)
Run Code Online (Sandbox Code Playgroud)
我是否将我的应用名称替换为'wsiapp'?我是否需要在顶级Django项目目录中运行它?
可能是一个令人困惑的问题标题.
具有红色矩形的网格是它应该如何看的示例.
具有蓝色矩形的网格(未出现在图像中)具有一个边距,迫使第二个网格小于我明确设置的网格.这似乎导致WPF翻转并隐藏其排列范围之外的所有内容.

我已经尝试将Clip设置为大于Grid.
我能够避免这种情况的唯一方法是编写一个自定义面板来测量它的具有PositiveInfinity约束的子节点,然后排列具有正确宽度的子节点.那种方法有很多问题.骗你的孩子是不好的.
无论如何,这是代码:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="NegativeMarginTooMuchClipping.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640"
Height="400">
<Grid>
<StackPanel Width="600" Height="300">
<Grid Margin="40,50,60,50" Background="#FFB8B8B8" Width="500" Height="50">
<Rectangle Fill="Red" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="50" Margin="0,-50,0,0"/>
</Grid>
<Grid Margin="40,50,61,50" Background="#FFB8B8B8" Width="500" Height="50">
<Rectangle Fill="Blue" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="50" Margin="0,-50,0,0"/>
</Grid>
</StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)
已知问题?我做错了吗?需要更多说明吗?