English 中文(简体)
当波段内的数据网捕获了烟雾时,烟pop自动关闭。
原标题:wpf popup doesn t close automatically when datagrid inside popup captures the mouse

页: 1 因此,我想通过点击人口以外的任何地方来结束。 在居民中,我有一个<代码>DataGrid。 如果我开诚布公,然后点击其他地方,则人口就会关闭。 但是,如果在登峰值一外点击,在的栏目上点击,就算不了。 测试XAML:

<Window x:Class="Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black">
<Grid>
    <ToggleButton x:Name="btn" VerticalAlignment="Top">Open</ToggleButton>
    <Popup StaysOpen="False" IsOpen="{Binding IsChecked, ElementName=btn}" > 
        <DataGrid Width="150" Height="150">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Column" />
            </DataGrid.Columns>
        </DataGrid>
    </Popup>
</Grid>
</Window>

我认为,这种情况之所以发生,是因为一栏头把烟.放在点击和烟火上,不会再发生 mo动。 我曾尝试在<代码>上添加一个手稿。 遗失的MouseCapture 为了通过人口来抓回 mo,但似乎不容易做事。 任何想法?

问题回答

Maybe it will help. Attached behavior:

public class DataGridColumnHeaderReleaseMouseCaptureBehavior {
    public static DataGrid GetReleaseDGCHeaderBehavior(DependencyObject obj) {
        return (DataGrid)obj.GetValue(ReleaseDGCHeaderBehaviorProperty);
    }

    public static void SetReleaseDGCHeaderBehavior(DependencyObject obj, Boolean value) {
        obj.SetValue(ReleaseDGCHeaderBehaviorProperty, value);
    }

    public static readonly DependencyProperty ReleaseDGCHeaderBehaviorProperty =
        DependencyProperty.RegisterAttached("ReleaseDGCHeaderBehavior",
            typeof(DataGrid),
            typeof(DataGridColumnHeaderReleaseMouseCaptureBehavior),
            new UIPropertyMetadata(default(DataGrid), OnReleaseDGCHeaderBehaviorPropertyChanged));

    private static Popup _popup;

    private static void OnReleaseDGCHeaderBehaviorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
        var oldGrid = (DataGrid)e.OldValue;
        if (oldGrid != null)
            oldGrid.MouseLeave -= OnMouseLeave;
        var refSender = d as Popup;
        _popup = refSender;
        if (refSender != null) {
            var refGrid = e.NewValue as DataGrid;
            if (refGrid != null) {
                refGrid.MouseLeave += OnMouseLeave;
            }
        }
    }
    static void OnMouseLeave(object sender, MouseEventArgs args) {
        if (_popup != null)
            typeof(Popup).GetMethod("EstablishPopupCapture", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(_popup, null);
    }
}

XAML:

<Popup x:Name="popup"
bhvrs:DataGridColumnHeaderReleaseMouseCaptureBehavior.ReleaseDGCHeaderBehavior="{Binding ElementName=dataGrid}">
  <DataGrid x:Name="dataGrid"/>
</Popup>

我认为,你 just倒了,只是一个老大的老杯。 我照此转载,找不到一条合理的办法。 我认为,你应该向微软公司提出ug。 这似乎像一个含有烟雾的成分,而且它没有把捕获物恢复到原先的捕获部分。

我最近也存在类似的问题,但并非完全一样,而是在银星。 我通过这一途径,在行为失控的必要活动中,寻找“GetTemplateParent”功能所需的控制(就你而言,我是老板),并在方案上做我想要做的事情。

这不是一个ice的解决办法,没有解决所有问题,但你可以尝试。 相信你会评论你所做的事,因为它可以变成一纸空文。

i) 存在同样的问题,而且情况类似:

 private void YourDataGrid_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
         YourDataGrid.CaptureMouse();
         YourDataGrid.ReleaseMouseCapture();
    }

但是,一米寻找更好的东西......





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签