小编Han*_*ish的帖子

未找到部署应用程序的MEF部件,但在调试模式下找到

我在这里检查了很多MEF问题,但我无法想象我的问题是什么.这是发生了什么:

我有一个桌面WPF应用程序,我正在部署AdvancedInstaller.我使用.NET 4.0和MEF来组成部件.某些部分位于主项目中,因此它们位于app.exe文件中.其他部分是引用主项目的类库内部,因此它们位于somename.dll文件中.

问题:从VS运行应用程序时,无论是在Debug还是在Release中,一切都很好.一旦我部署应用程序,一些dll说他们没有部分(零)导出.

我检查了以下内容:

  • 所有dll都在部署中可用,目录正在查找文件
  • 导出类型和名称是正确的,毕竟,在Visual Studio中一切正常
  • 当我尝试从dll添加部件时,我得到的部件数量仅在部署时为零.

这是在部署的应用程序中找不到部分的代码:

var catalog = new AggregateCatalog();
string path = Environment.CurrentDirectory.ToString();
DirectoryCatalog qualitycontrol = new DirectoryCatalog(".", "QualityControl.exe"); //this is my main assembly
DirectoryCatalog qualitymix;

catalog.Catalogs.Add(qualitycontrol); //this finds the parts and always works fine

if (File.Exists(path + @"\QualityMix.dll"))
{
    qualitymix = new DirectoryCatalog(".", "QualityMix.dll"); //the file exists in the deployment
    catalog.Catalogs.Add(qualitymix); //the "qualitymix" catalog shows more than 20 parts if run with VS, but 0 parts in deployment
}
Run Code Online (Sandbox Code Playgroud)

唯一可行的(但启动应用程序的速度非常慢)如下:

var catalog = …
Run Code Online (Sandbox Code Playgroud)

wpf dll plugins mef catalog

11
推荐指数
1
解决办法
448
查看次数

WPF UserControls:即使使用'x:Shared ="False"',图像也会消失

我在一个ResourceDictionary带有图像的按钮中定义了一个样式:

<Style x:Key="BotonIrAInicioStyle" TargetType="Button">
    <Setter Property="Margin" Value="0"/>
    <Setter Property="Width" Value="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"/>
    <Setter Property="Content">
        <Setter.Value>
            <Image Margin="2" Source="{StaticResource IconoDashboardBlanco}" MaxHeight="20" Stretch="Uniform"
                   RenderOptions.BitmapScalingMode="HighQuality"/>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

图像源ResourceDictionary在同一个程序集中的另一个中定义,并标记为x:Shared="False":

<BitmapImage x:Key="IconoDashboardBlanco" x:Shared="False"
UriSource="pack://application:,,,/QualityFramework;component/Images/dashboard64X64.png"/>
Run Code Online (Sandbox Code Playgroud)

由于样式将用于不同的程序集,我使用"pack://application:,,,"符号来引用图像.在Build Action对图像设置Resource (Do not copy to output directory).

在主程序集中,我有两个UserControls显示相同样式的按钮:

<Button DockPanel.Dock="Left" Style="{StaticResource BotonIrAInicioStyle}" Click="BotonIrAInicio_Click"/> (Click event has nothing to do with the problem)
Run Code Online (Sandbox Code Playgroud)

问题:

我打开UserControl A包含图像的按钮,图像显示确定.然后我打开UserControl B包含一个相同的按钮,图像确定.我UserControl A再次打开,图像消失了.如果我打开UserControl …

wpf resources xaml user-controls image

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

WPF将控件可见性绑定到另一个控件的focus属性

我有一个显示项目列表的组合框,我想在它旁边放一个按钮,触发命令查看所选项目的详细信息.到现在为止还挺好.现在我希望只有在组合框具有焦点(或处于"编辑"模式,但不仅仅是弹出窗口打开时)时按钮才可见.

我以为我可以将按钮的可见性绑定到组合框的某些焦点属性,如下所示:

<Button Content="Details" Visibility="{Binding ElementName=elementListComboBox,
Path=IsFocused, Converter={StaticResource Bool2VisibilityConverter}}"/>
Run Code Online (Sandbox Code Playgroud)

但我发现无法知道我想要的控制是否有重点.我查看了FocusManager.FocusedElement,但我不知道如何在绑定中获得我想要的聚焦控件.有没有办法在XAML中实现这一目标?

wpf xaml binding controls

4
推荐指数
1
解决办法
6910
查看次数

如何获取 NotifyCollectionChangedEventArgs 中更改的项目?

我创建了一个 ObservableCollection<T> ,每当集合中对象的属性 (T: INPC) 发生更改时,它都会触发 CollectionChangedEvent。我想知道 T 的哪个属性触发了 CollectionChangedEvent,所以我尝试了以下操作:

    void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset, e));
    }
Run Code Online (Sandbox Code Playgroud)

我将 PropertyChangedEventArgs e 传递给 NotifyCollectionChangedEventArgs 的构造函数。

根据 Intellisense,第二个构造函数采用两个参数:NotifyCollectionChangedAction 和一个名为“changedObject”的对象,该对象被描述为“受更改影响的项目”。

所以我想我可以在 CollectionChangedEventHandler 中获取该对象并检查 PropertyName,但是哦!惊喜!NotifyCollectionChangedEventArgs 不公开“ChangedObject”属性(我可以看到 Action、NewItems、OldItems、NewStartingIndex、OldStartingIndex)。

关于如何实现这一目标有什么想法吗?顺便问一下,使用稍后无法访问的对象构造 NotifyCollectionChangedEventArgs 有什么用处?

c# observablecollection inotifycollectionchanged inotifypropertychanged

3
推荐指数
1
解决办法
6757
查看次数

WPF MVVM依赖项属性

我有以下情况:

  1. 我有一个用户控件,里面只有一个Grid.
  2. Grid的第一列是复选框列,它绑定到CustomerModel的IsSelected属性
  3. Grid的ItemsSource绑定到List <CustomerModel>
  4. 当用户检查任何CheckBox时,CustomerModel的相应IsSelected属性正在更新

查询:

  1. 我向UserControl添加了一个名为"SelectedCustomerItems"的依赖属性,我希望它返回一个List <CustomerModel>(仅用于IsSelected = true)

  2. 此UserControl放在另一个窗口上

  3. 依赖属性"SelectedCustomerItems"绑定到WindowViewModel中的"SelectedCustomers"属性

但我没有通过此依赖项属性获取SelectedCustomer项.断点没有打到Get {}请建议....

wpf dependency-properties mvvm wpf-controls

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