小编use*_*959的帖子

如何通过编程方式解除DevExpress的所有WPF菜单,弹出窗口等,以解决与WindowsFormsHost相关的问题?

我希望它的行为就像你在应用程序上的某个地方点击一样.(折叠所有菜单,下拉等)

实际上,我正在尝试解决您在WPF应用程序中托管Windows窗体控件时遇到的与互操作性相关的焦点问题WindowsFormsHost:如果DevExpress的WPF菜单/弹出窗口打开并且您单击Windows窗体控件,则菜单/ popup不会自动被解雇.

现在我WindowsFormsHost在WPF区域中有很多Windows Forms控件以及很多DevExpress控件.为了轻松解决这个问题,我添加了一个消息过滤器来挂钩应用程序中的所有点击,然后我看看点击的控件是否是Windows窗体控件.然后我需要做一些事情来使DevExpress的所有WPF菜单等被解雇,如果它们是开放的.

GlobalMouseHandler globalClick = new GlobalMouseHandler();
System.Windows.Forms.Application.AddMessageFilter( globalClick );
Run Code Online (Sandbox Code Playgroud)

GlobalMouseHandler:

public class GlobalMouseHandler : System.Windows.Forms.IMessageFilter
{
  private const int WM_LBUTTONDOWN = 0x201;
  private const int WM_RBUTTONDOWN = 0x204;

  public bool PreFilterMessage( ref System.Windows.Forms.Message m )
  {
    if( m.Msg == WM_LBUTTONDOWN || m.Msg == WM_RBUTTONDOWN )
    {
      var c = System.Windows.Forms.Control.FromHandle( m.HWnd );

      if( c != null )
        // TODO: CLOSE ALL WPF MENUS ETC
        // Didn't work: MainWindow.Instance.ARandomControl.Focus();
    }

    return false;
  } …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf devexpress windowsformshost

14
推荐指数
1
解决办法
884
查看次数

为什么我的.net项目中.net framework 3.5的System.dll版本是2.x?

我有一个针对.net框架3.5的解决方案.所有对核心dll的引用都具有运行时版本2.x,因为它们是使用它编译的.为什么会这样?这是否意味着我没有使用那些带有错误修复的DLL的最新版本?

.net dll .net-3.5 visual-studio-2008 .net-2.0

6
推荐指数
1
解决办法
1945
查看次数

从另一个AppDomain接收程序集引用时的异常

我正在从新的AppDomain中的特定"扩展"目录加载所有DLL,以从中获取一些与Reflection相关的信息.

这就是我正在尝试的:

AssemblyProxy在我的解决方案中创建了一个新库,它只有这个类:

public class AssemblyProxy : MarshalByRefObject
{
    public Assembly LoadFile( string assemblyPath )
    {
      try
      {
        return Assembly.LoadFile( assemblyPath );
      }
      catch
      {
        return null;
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

我确保这个DLL存在于我的"extensions"目录中.然后我使用以下代码将"extensions"目录中的所有程序集加载到新的程序集中AppDomain.

foreach( string extensionFile in Directory.GetFiles( ExtensionsDirectory, "*.dll" ) )
{
        Type type = typeof( AssemblyProxy.AssemblyProxy );
        var value = (AssemblyProxy.AssemblyProxy) Domain.CreateInstanceAndUnwrap(
            type.Assembly.FullName,
            type.FullName );

        var extensionAssembly = value.LoadFile( extensionFile );

        types.AddRange( extensionAssembly.GetTypes() );
}
Run Code Online (Sandbox Code Playgroud)

一些DLL确实成功加载,但在某些DLL上会抛出异常,如下所示:

Could not load file or assembly 'Drivers, Version=2.3.0.77, Culture=neutral, PublicKeyToken=null' …

.net c# dll appdomain

6
推荐指数
1
解决办法
764
查看次数

ComboBox在更改DataContext时触发旧DataContext的触发

因此,我NewMyItem在视图模型中保留一个对象作为DataContext负责在列表中添加新项的控件.每当AddCommand执行时,我重置该对象,以便它可以添加另一个项目.

我在这里遇到的问题是,只要在Add方法内重置了对象,就会为刚添加的项目SelectionChanged不必要地引发组合框的触发器.它不应该首先被解雇,但即使被解雇,为什么它会被解雇?DataContext

如何避免这种情况,因为我需要在触发器的命令中放置一些业务逻辑,我不能运行两次?

这是一个简单的示例,展示了我面临的问题:

XAML:

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:local="clr-namespace:WpfApplication2"
        Title="MainWindow" Height="350" Width="525"
        DataContext="{Binding RelativeSource={RelativeSource Self}}">

    <Window.Resources>
        <local:ChangeTypeConverter x:Key="changeTypeConverter" />

        <local:MyItems x:Key="myItems">
            <local:MyItem Name="Item 1" Type="1" />
            <local:MyItem Name="Item 2" Type="2" />
            <local:MyItem Name="Item 3" Type="3" />
        </local:MyItems>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" DataContext="{Binding DataContext.NewMyItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MainWindow}}}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions> …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf triggers

5
推荐指数
1
解决办法
635
查看次数

如何从其Resources部分内部绑定到数据绑定的UserControl?

我要绑定ParentSidebarSelectIngredient到根Sidebar以下XAML.DataContextSidebar,所以我不能用它设置一些数据在后台代码.我想在不使用的情况下实现这一点ElementName.可能吗?

<Sidebar x:Class="MyApplication.Sidebar"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Sidebar.Resources>
        <SelectIngredient x:Key="selectIngredient" x:Name="selectIngredient"
                              ParentSidebar="{Binding ???}">
        </SelectIngredient>
    </Sidebar.Resources>

</Sidebar>
Run Code Online (Sandbox Code Playgroud)

编辑:

在Visual Tree中,Sidebar是一个兄弟姐妹SelectIngredient.所以它只是逻辑上的父母,但实际上并非如此.

c# data-binding wpf xaml mvvm

0
推荐指数
1
解决办法
42
查看次数