小编Mod*_*ndi的帖子

ListViewItem自定义模板:ContentPresenter保持为空

我的代码中有以下ListView.views:GameCard是一个自定义UserControl,{Binding}是一个DataContext有三个项目的有效对象.没有自定义ItemContainerStyle一切都很完美 - 列表显示三个GameCards正确的信息等.一旦我添加ItemContainerStyle部分,我只得到三个"ABCD"; 所以数据仍然正确加载,但我UserControl不再显示(我只添加"ABCD"来检查数据是否存在,否则我只得到空盒子).

我在网上找到的每一条信息似乎都表明只是ContentPresenter在模板中放置一个元素应该可以工作,但在这种情况下似乎并不存在.我错过了什么?

<ListView Grid.Row="1" ItemsSource="{Binding}" BorderThickness="0,0,1,0"
              ScrollViewer.HorizontalScrollBarVisibility="Disabled">
    <ListView.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FF614B4B" Offset="0"/>
            <GradientStop Color="#FFDA7070" Offset="1"/>
        </LinearGradientBrush>
    </ListView.Background>
  <ListView.ItemsPanel>
    <ItemsPanelTemplate>
      <WrapPanel />
    </ItemsPanelTemplate>
  </ListView.ItemsPanel>
  <ListView.ItemTemplate>
    <DataTemplate>
      <views:GameCard />
    </DataTemplate>
  </ListView.ItemTemplate>
  <ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate>
            <Grid>
              <TextBlock Text="ABCD" />
              <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </ListView.ItemContainerStyle>
</ListView>
Run Code Online (Sandbox Code Playgroud)

wpf xaml templates contentpresenter listviewitem

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

CertificateStore的Certificates.Find()实际上并没有找到证书

\n这是我的简单方法:

\n\n
private static X509Certificate2 GetCertificateFromStore(StoreLocation storeLocation, string certName) {\n    var store = new X509Store(StoreLocation.LocalMachine);\n    try {\n        store.Open(OpenFlags.ReadOnly);\n        var certs = store.Certificates.Find(X509FindType.FindBySubjectName, certName, true);\n        return certs.Count == 0 ? null : certs[0];\n    }\n    finally {\n        store.Close();\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

调试本地显示store.Certificates已加载并包含两个证书 \xe2\x80\x94 默认的“localhost”一个和一个我已导入的证书,因此正确的存储已成功打开。

\n\n

但是,该Find()方法始终返回空结果,无论我搜索哪个证书以及是否使用FindBySubjectNameFindByThumbprint

\n\n

有什么想法可能是错的吗?它是一个简单的控制台应用程序,创建的唯一目的是学习和测试证书加载,即项目配置或其他任何地方几乎没有任何内容是默认的。

\n

c# certificate

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

在Spring中手动解决依赖关系[启动]

似乎应该没什么大不了的,但是Google和StackOverflow似乎都与Spring文档一样不合作(或者我只是不知道在哪里看)。

我的Spring Boot应用程序需要手动实例化某些类。有些类具有依赖关系,所以我不能使用.newInstance(); 相反,我想我需要让Spring从其DI容器中给我该实例。就像是

Class<? extends Interface> className = service.getClassName();
Interface x = SpringDI.getInstance(className);
Run Code Online (Sandbox Code Playgroud)

但是我似乎找不到任何办法。我该怎么办?

编辑

类名是动态解析的,我已经更新了示例pseuido代码以反映这一点。

java spring dependency-injection spring-boot

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