小编Kap*_*íko的帖子

资源的路径作为按钮的内容

我想设置ButtonContentPath中定义Resources.所以我在资源中创建UserControl,定义了Path两个Brushes按钮Style......一切都很好.

<UserControl ...>
    <UserControl.Resources>
        <Path x:Key="PageSmallIcon2" Stretch="Fill" Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}, Path=Foreground}" Stroke="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}, Path=Foreground}" SnapsToDevicePixels="True" Data="F1 M 19,25L 27,25L 27,33L 19,33L 19,25 Z M 19,36L 27,36L 27,44L 19,44L 19,36 Z M 31,25L 57,25L 57,33L 31,33L 31,25 Z M 19,47L 27,47L 27,55L 19,55L 19,47 Z "/>
        <SolidColorBrush x:Key="MainColorBrush2" Color="Orange"/>
        <SolidColorBrush x:Key="WhiteColorBrush2" Color="WhiteSmoke"/>
        <Style x:Key="TransparentButtonStyle2" TargetType="{x:Type Button}">
            <Setter Property="Foreground" Value="{StaticResource WhiteColorBrush2}"/> …
Run Code Online (Sandbox Code Playgroud)

wpf xaml wpf-controls

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

T4模板和Assembly.Load

这是我在StackOverflow上的第一个问题,所以嗨:)

是否可以使用T4模板中的Assembly.Load()按程序集名称加载程序集?我想用它来获取加载程序集中具有ServiceContract属性的所有类型.

    var loadedAssembly = Assembly.Load(assemblyName);
    var types = from type in loadedAssembly.GetTypes()
    where Attribute.IsDefined(type, typeof(ServiceContractAttribute))select type;
Run Code Online (Sandbox Code Playgroud)

在我的模板所在的项目中引用所需的程序集.我想通了

    <#@ assembly name="$(TargetDir)\DesiredAssemblyName.dll" #>
    var loadedAssembly = Assembly.GetAssembly(typeof(SomeType));
Run Code Online (Sandbox Code Playgroud)

有效,但它似乎不是一个好的解决方案.此外,我希望该模板在构建后以及向.csproj添加以下行时进行转换

      <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\
         TextTemplating\v10.0\Microsoft.TextTemplating.targets"/>
      <PropertyGroup>
         <TransformOnBuild>true</TransformOnBuild>
      </PropertyGroup>
      <ItemGroup>
         <!--Add VS\...\PublicAssemblies to the list of places
         to look for assemblies used by templates.--> 
         <T4ReferencePath Include="..\Onii.Vespa.AppServer\"/>
      </ItemGroup>
Run Code Online (Sandbox Code Playgroud)

使用Assembly.GetAssembly的解决方案也不起作用.谢谢你的所有建议.

.net c# t4

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

WPF TextBlock文本绑定

TextBlock绑定不起作用,我不知道为什么......

(此代码有效,但TextBlock未更新)

XAML

<TextBlock x:Name="filterAllText"
 Text="{Binding UpdateSourceTrigger=PropertyChanged}" />
Run Code Online (Sandbox Code Playgroud)

代码隐藏

filterAllText.DataContext = LogSession.test.MyCoynt;
Run Code Online (Sandbox Code Playgroud)

C#

public class Test : INotifyPropertyChanged {
 public int myCoynt;

     public int MyCoynt {
        get { return myCoynt; }
        set {
            myCoynt = value;
            NotifyPropertyChanged();
        }
    }

     public event PropertyChangedEventHandler PropertyChanged;

     protected virtual void NotifyPropertyChanged(
        [CallerMemberName] String propertyName = "") {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null) {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
}
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf user-controls

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

从DataGrid单元格复制文本

我希望能够从DataGrid Cell复制文本.

  1. 第一种可能的解决方案可能是设置SelectionUnit,Cell但这不是我的选择,因为我需要选择FullRow
  2. 第二种可能的方法是在DataGridTemplateColumn其中使用readonly TextBox.但是样式存在问题.我之前的问题:DatagridCell样式被TextBox样式覆盖.我需要非常明亮的颜色用于行中的文本,但在选定的行中确实很暗.
  3. 三是设置DataGrid的IsReadOnly ="假",并提供EditingElementStyleDataGridTextColumn

    <Style x:Key="EditingStyle" TargetType="{x:Type TextBox}">
    <Setter Property="IsReadOnly" Value="True"/>
    </Style>
    ...  
    <DataGridTextColumn ... EditingElementStyle="{DynamicResource EditingStyle}"/>
    
    Run Code Online (Sandbox Code Playgroud)

    但是这里出现了一个非常可怕的错误WPF Datagrid文本列允许在内部文本框设置为只读时输入一个字符文本.

你知道一些不同的解决方案吗?或解决方法?谢谢.

编辑

我注意到,DataGrid扩展WPF工具包没有这个错误,但它似乎有不同的结构,我不能应用我的DataGrid样式.

我注意到使用ReadOnly TextBox作为DataGridColumn的EditingElementStyle会带来更多问题.当您使用OneWay绑定时,不可能将单元格设置为编辑状态.让用户覆盖DataGrid中显示的某个实体的ID,这是不可接受的.所以它必须以某种方式只读或至少OneWay绑定.

此刻我完全无法解决这个问题.在选择并突出显示行时,是否有其他方法让用户从单元格复制?我没有注意到其他一些解决方案吗?谢谢阅读.

c# wpf datagrid mvvm

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

我可以在WPF网格中获取标题从数据模板中获取行吗?

我正在使用彼此之上的网格实现一个带标题的表,所以我可以指定列标题.标题有一个网格,表格中的每一行都有一个网格.它不是很实用,标题宽度必须指定两次.也许我可以拥有一个没有所有样式的ListView/DataGrid?

如何摆脱这种多网格方法?

这是我得到的:

<StackPanel Orientation="Vertical">
  <Grid Margin="0, 10, 0, 0">
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="40" />
      <ColumnDefinition Width="70" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition />
    </Grid.RowDefinitions>
    <TextBlock Grid.Column="0" Grid.Row="0"
            Text="header 1" />
    <TextBlock Grid.Column="1" Grid.Row="0"
            Text="header 2" />
  </Grid>
  <ItemsControl ItemsSource="{Binding Entities}">
    <ItemsControl.ItemTemplate>
      <DataTemplate>
        <StackPanel Orientation="Vertical">
          <Grid Margin="0, 10, 0, 0">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="40" />
              <ColumnDefinition Width="70" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition />
            </Grid.RowDefinitions>
            <TextBlock Grid.Column="0" Grid.Row="0"
               Text="{Binding Property1}" />
            <TextBlock Grid.Column="1" Grid.Row="0"
               Text="{Binding Property2}" />
          </Grid>
        </StackPanel>
      </DataTemplate>
    </ItemsControl.ItemTemplate>
  </ItemsControl>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

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

WSHttpBinding TransportWithMessageCredential SecurityMode 更改请求

我正在努力处理WCF绑定配置。我添加了第三方服务作为我的项目的参考。我得到了一些规格。

我需要使用,SOAP v1.2所以我想我需要WSHttpBinding它,https所以我需要SecurityMode.Transport

像这样的东西:

var binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
var client = new MyClient(binding, addr);
var result = client.Method(new MyObject());
Run Code Online (Sandbox Code Playgroud)

它会产生此请求正文。

var binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
var client = new MyClient(binding, addr);
var result = client.Method(new MyObject());
Run Code Online (Sandbox Code Playgroud)

根据我提供的规范,我需要在标头中包含和Security元素。正是我想要得到的和UsernameTokenTimestampBasicHttpBindingBasicHttpSecurityMode.TransportWithMessageCredential

当我尝试使用请求正文设置TransportWithMessageCredential模式时WSHttpBinding,请求正文会发生巨大变化。

binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
var client = new MyClient(binding, addr);
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password …
Run Code Online (Sandbox Code Playgroud)

c# wcf ws-security soap web-services

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

前缀'xcdg'不映射到命名空间

我最近开始使用Extended WPF Toolkit中的DataGridControl

<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}">
    <xcdg:DataGridControl ItemsSource="{Binding Orders}" SelectionMode="Single" >
        <xcdg:DataGridControl.View>
            <xcdg:TableflowView FixedColumnCount="1" UseDefaultHeadersFooters="True" ShowRowSelectorPane="False" VerticalGridLineBrush="Green" VerticalGridLineThickness="2" HorizontalGridLineBrush="Purple" HorizontalGridLineThickness="2">
                <xcdg:TableflowView.Theme>
                    <xcdg:ZuneNormalColorTheme/>
                </xcdg:TableflowView.Theme>
            </xcdg:TableflowView>
        </xcdg:DataGridControl.View>
        <xcdg:DataGridControl.Columns>
            <xcdg:Column FieldName="OrderID" IsMainColumn="True"/>
            <xcdg:Column FieldName="ExternalID" />
            <xcdg:Column FieldName="CustomerName" />
            <xcdg:Column FieldName="Date" />
            <xcdg:Column FieldName="Address" />
            <xcdg:Column FieldName="Items" Width="*" />
        </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>
</Grid>
Run Code Online (Sandbox Code Playgroud)

没关系,一切正常.然后我添加了风格.

<Style TargetType="{x:Type xcdg:DataGridControl}">
    <Setter Property="Background" Value="MediumOrchid"/>
</Style>
Run Code Online (Sandbox Code Playgroud)

Style应用,一切都恢复正常.所以我接下来要做的就是CotrolTemplate使用Expression Blend 创建并将该模板添加到我的Style中.

<Style TargetType="{x:Type xcdg:DataGridControl}">
  <Setter Property="Background"
          Value="MediumOrchid" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type xcdg:DataGridControl}">
        <Grid>
          <Border BorderBrush="{TemplateBinding …
Run Code Online (Sandbox Code Playgroud)

wpf xaml controltemplate xceed-datagrid

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

如何从PrepareToInstall事件函数设置StatusMsg

我的应用程序需要安装.NET Framework,因此我在PrepareToIntall事件函数中运行.NET安装.在安装运行时,我想在向导上显示一些简单的消息.

我找到了如何在Inno安装脚本的[Code]部分设置状态消息?但那里的解决方案对我不起作用.

我试过了

WizardForm.StatusLabel.Caption := CustomMessage('InstallingDotNetMsg');
Run Code Online (Sandbox Code Playgroud)

并且

WizardForm.PreparingLabel.Caption := CustomMessage('InstallingDotNetMsg');
Run Code Online (Sandbox Code Playgroud)

编辑

我必须在PrepareToInstall函数中执行此操作,因为我需要在.net安装失败时停止设置.

代码现在看起来像这样:

function PrepareToInstall(var NeedsRestart: Boolean): String;
var 
   isDotNetInstalled : Boolean;
   errorCode : Integer;
   errorDesc : String;
begin
   isDotNetInstalled := IsDotNetIntalledCheck();
   if not isDotNetInstalled then 
   begin
      //WizardForm.PreparingLabel.Caption := CustomMessage('InstallingDotNetMsg');
      WizardForm.StatusLabel.Caption := CustomMessage('InstallingDotNetMsg');
      ExtractTemporaryFile('dotNetFx40_Full_x86_x64.exe');
      if  not ShellExec('',ExpandConstant('{tmp}\dotNetFx40_Full_x86_x64.exe'),'/passive /norestart', '', SW_HIDE, ewWaitUntilTerminated, errorCode) then
      begin
        errorDesc := SysErrorMessage(errorCode);
        MsgBox(errorDesc, mbError, MB_OK);
      end; 
      isDotNetInstalled := WasDotNetInstallationSuccessful();
      if not isDotNetInstalled then
      begin
         Result := CustomMessage('FailedToInstalldotNetMsg');
      end; …
Run Code Online (Sandbox Code Playgroud)

inno-setup

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

Htaccess - 用正斜杠替换.html

我想重定向此表单的网址: /page.html?variable=value&othervar=true&thirdvar=100

对此: /page/?variable=value&othervar=true&thirdvar=100

所以基本上我只想用a 替换.html中间,但我需要保留随附的get字符串.这是我试过的:URLforward slash

RewriteRule ^ page.html(.+)$/page/$ 1 [L,R = 301]

但这似乎对我不起作用.我最近做了类似的事情,但我无法弄清楚我在这里缺少什么.感谢您的任何意见.

.htaccess mod-rewrite redirect

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