小编Ing*_*als的帖子

如何在WPF中重用布局

我正在尝试创建一个应用选项卡,其中每个选项卡都有一个按钮区域和一个视图区域.

现在每个选项卡在布局中基本上具有相同的布局,我希望能够重用相同的布局,这样我就不必在很多地方进行更改(这只是不好的编程).我可以使用资源或样式完成此操作.

如果可能,请提供灯光代码示例.

编辑:我已经决定添加一个我正在尝试做的例子,因为我还没有得到它.

在每个TabItem下我试图重新创建这个网格(它有点复杂,但你明白了):

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

        <Border Margin="10"
                            BorderBrush="{StaticResource MediumColorBrush}"
                            CornerRadius="10"
                            BorderThickness="2"
                            Grid.Row="0">

               <!-- First content goes here -->

        </Border>

        <Border Margin="10"
                            BorderBrush="{StaticResource MediumColorBrush}"
                            CornerRadius="10"
                            BorderThickness="2"
                            Grid.Row="1">

               <!-- Second content goes here -->

        </Border>

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

你也可以看到2个边框是一样的.现在我需要将一些内容占位符放在我的评论所在的位置.我不想在资源字典中声明这个Grid布局,然后在我使用它的地方将单独的内容放入每个边框.

我可能有很多TabItems,所以重复这段代码不是一个好主意,每个Tab页面将在2个占位符中有不同的内容.

我可以用了

<ContentPresenter Content="{Binding}" />
Run Code Online (Sandbox Code Playgroud)

只有1个内容的东西,当会有更多内容时会发生什么.

wpf layout styles resourcedictionary

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

如何在Linq-to-XML中按路径查找XML节点

如果我得到一个特定节点的路径作为字符串,我可以通过使用XElement(或XDocument)的Linq /方法以某种方式轻松找到所述节点.

有很多不同类型的XML对象,如果作为一个额外的奖励,你可以指出我为什么/如何使用不同类型的指南.

编辑:确定在指向XPathSelectElement后我正在尝试它,所以我可以给他正确的答案我不能让它工作但是.这是我正在尝试的XML

<Product>
  <Name>SomeName</Name>
  <Type>SomeType</Type>
  <Quantity>Alot</Quantity>
</Product>
Run Code Online (Sandbox Code Playgroud)

和我的代码

string path = "Product/Name";
string name = xml.XPathSelectElement(path).Value;
Run Code Online (Sandbox Code Playgroud)

请注意我的字符串来自其他地方,所以我猜它不一定是文字(至少在调试模式下它看起来像上面那个).我也尝试过添加/在前面.它给了我一个空参考.

c# xml xpath linq-to-xml

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

流入包,打包到WordDocument然后再返回

我不了解Streams周围的所有机制,甚至不太了解System.IO.Package全班.

我有一个.docx文件作为数据库中的二进制文件,我不想获取它,稍微修改然后保存它.

我目前有一个在单独的库中修改文档的方法,因为它将在许多地方使用.

这就是我尝试这样做的方式:

byte[] doc = getDocFromDB();
using (MemoryStream mem = new MemoryStream())
{
    mem.Write(doc, 0, doc.Length);

    Package pack = Package.Open(mem, FileMode.Open, FileAccess.ReadWrite);
    filler.FillTemplate(ref pack, someIrreleventData);

    string filePath = Path.GetTempPath() + "docname.docx";

    using (FileStream file = new FileStream(filePath, FileMode.Create))
    {
        mem.WriteTo(file);
        file.Flush();
        file.Close();
    }

    Process.Start(filePath);
}
Run Code Online (Sandbox Code Playgroud)

库代码如下所示:

public void FillTemplate(ref Package package, XElement data)
{
    WordprocessingDocument document = WordprocessingDocument.Open(package);

    //add the data to the document

    //should I do document.close() or document.dispose() here?

}
Run Code Online (Sandbox Code Playgroud)

该文档就像它保存到数据库中一样,没有添加所有额外数据.

我假设我打开包含内存流的包,所有对包的更改也将保存到流中. …

c# stream package openxml-sdk

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

带有变量Dynamic DisplayName的DisplayAttribute名称

想知道这是否可能或具有这种效果的东西.

public class MyModel
{
    public string Name { get; set; }

    [Display(Name = String.Format("This is [0]'s phone number", Name)]
    public string PhoneNumber { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我在谈论一个带有变量的DisplayName,非静态的,可能还基于模型的其他属性.这有可能吗?

c# string-formatting data-annotations displayattribute

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

C#:在非泛型类中实现两个抽象列表?

对于这个愚蠢的标题感到抱歉,不知道怎么说这个

我正在创建一个具有两个相同类型列表的类.它用于将对第一个列表中的对象的引用复制到第二个列表.

虽然两个列表的类型相同(保持相同类型的对象),但每次初始化此类时它们可能不同.

所以我猜我应该将List类型作为某种抽象列表.我想确保它们在实例化时会被强类型化(但如果有问题,则不是必需的).问题出在将所选项从list1移动到list2的方法内部.抽象列表类型通常没有方法.

我想正常的解决方案是使类通用(className <T>thingy),但我不确定我能做到(至少我不知道如何),因为这个类继承了WPF UserControl.

这是代码:

public partial class SubsetSelectionLists : UserControl
{
    public static DependencyProperty SetCollectionProperty = DependencyProperty.Register("SetCollection", typeof("Need a abstract list type here"), typeof(SubsetSelectionLists));
    public static DependencyProperty SubsetCollectionProperty = DependencyProperty.Register("SubsetCollection", typeof("Need a abstract list type here"), typeof(SubsetSelectionLists));

    public "Need a abstract list type here" SetCollection
    {
        get
        {
            return ("Need a abstract list type here") GetValue(SetCollectionProperty);
        }
        set
        {
            SetValue(SetCollectionProperty, value);
        }
    }

    public "Need a abstract list type here" SubsetCollection
    {
        get
        {
            return …
Run Code Online (Sandbox Code Playgroud)

c# generics collections user-controls abstract-class

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

在Asp.Net MVC中,我对身份验证模式有哪些其他选择?

在Web.config文件中,这条信息就在那里

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
Run Code Online (Sandbox Code Playgroud)

我可以设置其他模式,我可以有多种模式吗?

一些用户可以使用username/pass登录,其他用户使用x509 clientCert登录.

哪里有关于此的信息?

forms-authentication client-certificates asp.net-mvc-3

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

包装属性设置器

我发现自己很重复,这当然不好.所以我想知道我是否可以为此做些什么.这是我的WPF应用程序中的常见代码:

private string _name;
public string Name
{
    get { return _name; }
    set
    {
        if (_name != value)
        {
            _name = value;
            OnPropertyChanged("Name");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我想知道我是否可以以某种方式包装setter以使其更好,更具可读性.一个想法是这样的:

protected void PropertySetter<T>(T property, T value, string name)
{
    if (EqualityComparer<T>.Default.Equals(property, value))
    {
        property = value;
        OnPropertyChanged(name);
    }
}
Run Code Online (Sandbox Code Playgroud)

用法如下:

private string _name2;
public string Name2
{
    get { return _name2; }
    set
    {
        PropertySetter<string>(Name2, value, "Name2");
    }
}
Run Code Online (Sandbox Code Playgroud)

但我不确定这是非常聪明还是与Value类型一样好用?

我想我不是第一个尝试这样的事情的人,所以如果有人知道这样的事情是一个很好的万无一失的方式,请加入.我想我不能让财产改变类型安全没有反思,但任何想法也会有所帮助.

c# properties wrapper

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

WPF:ComboBox TextSearch,它是如何工作的?

假设组合框中的Textsearch在Combobox顶部给出了一个文本输入框,当我输入时会过滤掉,我是否正确?

如果是这样,我不明白为什么它不起作用.我有一个组合框,它的itemssource通过DataContext绑定到ListCollectionView.我将IsTextSearchEnabled设置为true并将TextSearch.TextPath设置为ListCollectionView中对象类型的属性

 <ComboBox ItemsSource="{Binding Path=PersonCollection}"
           TextSearch.TextPath="Name"   DisplayMemberPath="Name" IsTextSearchEnabled="True" >
                    </ComboBox>
Run Code Online (Sandbox Code Playgroud)

但是我从来没有得到任何输入框.

属性defo的工作原理与我在DisplayMemberPath中设置的一样.

我是假设错了,如果是这样,文本搜索是如何工作的?

c# wpf combobox

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

WPF:由于样式和/或修改的列表框,Groupstyle 无法正常工作

我正在尝试使用 GroupStyle,但不是将组名显示为列表中项目的标题,而是仅显示标题而不显示项目。

它工作得很好,直到我对列表应用了特殊的样式。然后我认为这种风格非常虚假,所以我为这种效果创建了一个用户控件。问题仍然存在。

UserControl 的目的是对所选项目产生扩展效果,通常它可以显示一些信息,然后在扩展时显示更多信息。

用户控制:

<UserControl x:Class="MyProject.CustomUC.ExpandingList"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">

    <Grid>
        <ListBox x:Name="List"
                 ItemsSource="{Binding Path=Collection}">
            <ListBox.Template>
                <ControlTemplate TargetType="ListBox">
                    <Border BorderBrush="Blue" 
                                    BorderThickness="1" 
                                    CornerRadius="2" 
                                    Background="White">
                        <ScrollViewer Focusable="False">
                            <StackPanel Margin="2" IsItemsHost="True" />
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </ListBox.Template>
            <ListBox.GroupStyle>
                <GroupStyle HidesIfEmpty="True">
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Name}"/>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListBox.GroupStyle>
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <Border Margin="4" Name="Border" BorderBrush="Blue" BorderThickness="1" CornerRadius="5" Background="LightBlue">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <ContentPresenter Name="Head"
                                                          Margin="4"
                                                      Visibility="Visible"
                                                      ContentTemplate="{Binding ElementName=List, Path=DataContext.HeadTemplate}"/>
                                        <Border …
Run Code Online (Sandbox Code Playgroud)

wpf listbox groupstyle

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

引导表中的输入宽度始终使用最大宽度

好的,我试图用输入字段做一个表.要设置每个字段的大小我理解我必须在标题中设置col-size.

<thead>
    <tr>
        <th class="col-sm-2">Large</th>
        <th class="col-sm-2">Large</th>
        <th class="col-sm-1">Small</th>
        <th class="col-sm-2">Large</th>
        <th class="col-sm-1">Small</th>
        <th class="col-sm-2">Large</th>
        <th class="col-sm-2">Large</th>
    </tr>
</thead>
Run Code Online (Sandbox Code Playgroud)

然而,输入扩展到它们的最大宽度而不考虑col-size.

http://jsfiddle.net/m79HR/

可能这是对Bootstrap的不当使用,但我认为它是带有标题的内联输入的最佳选择.

另外,假设我希望这个特定的网格有18列,而不是默认的12,这可能就在这个特殊情况下?

html css twitter-bootstrap twitter-bootstrap-3

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