小编Phi*_*oie的帖子

WPF XAML:如何禁用DataGrid中的多选?

在像这样的DataGrid中:

<DataGrid  AutoGenerateColumns="False" Height="200" Name="dataGrid"
    IsReadOnly="True" ItemsSource="{Binding CollectionView}" >
...
</Datagrid>
Run Code Online (Sandbox Code Playgroud)

如何禁用多选功能?

(我确信这很简单,但我找不到.)

wpf xaml datagrid multi-select

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

通过对象初始化设置属性与否:任何区别?

这是一个简单的问题:这之间是否存在任何(性能)​​差异:

Person person = new Person()
{
  Name = "Philippe",
  Mail = "phil@phil.com",
};
Run Code Online (Sandbox Code Playgroud)

还有这个

Person person = new Person();
person.Name = "Philippe";
person.Mail = "phil@phil.com";
Run Code Online (Sandbox Code Playgroud)

您可以想象具有更多属性的更大对象.

c# setter performance properties object-initialization

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

WPF绑定:对ValidationRules使用DataAnnotations

我已经阅读了很多关于WPF验证的博客文章DataAnnotations.我在想,如果有使用干净的方式DataAnnotations作为ValidationRules对我的实体.

所以没有这个(来源):

<Binding Path="Age" Source="{StaticResource ods}" ... >
  <Binding.ValidationRules>
    <c:AgeRangeRule Min="21" Max="130"/>
  </Binding.ValidationRules>
</Binding>
Run Code Online (Sandbox Code Playgroud)

你必须拥有你的

public class AgeRangeRule : ValidationRule 
{...}
Run Code Online (Sandbox Code Playgroud)

我希望WPF Binding能够看到Age属性并查找DataAnnotation,如下所示:

[Range(1, 120)]
public int Age
{
  get { return _age; }
  set
  {
    _age = value;
    RaisePropertyChanged<...>(x => x.Age);
  }
}
Run Code Online (Sandbox Code Playgroud)

任何想法,如果这是可能的?

wpf binding validationrules data-annotations

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

VS2010项目之间的程序集引用失败

语境:

我的解决方案中有3个项目(C#,.NET 4.0):

  • Abc.Business(Dll项目)
  • Abc.Test(测试项目)
  • Abc.Ui(Wpf项目)

  • Abc.Business是我的业务逻辑.它包含实体,经理,服务等.

  • Abc.Test有关于Abc.Business的项目参考,是单元测试.他们运作良好.
  • Abc.Ui有关于Abc.Business的项目参考

Abc.Ui无法解析所有using Abc.Business; 错误日志显示:

错误名称空间'Abc'中不存在类型或命名空间名称'Business'(您是否缺少程序集引用?)c:\ Abc\Abc.Ui\ViewModels\ClientViewModel.cs

此外,当我手动输入using文件的顶部时,Intelli-sense会显示" Abc.Business.etc .. ".所以Intelli-sense走在引用中但是没有构建.

有任何想法吗 ?

c# assemblies projects-and-solutions visual-studio-2010

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

CAML查询到SharePoint列表,按查找字段排序

我正在尝试通过CAML从SharePoint中提取列表,我希望按特定字段排序返回的列表.该字段是查找字段.当我将OrderBy设置为查找字段时,查询返回无序,如果我使用文本字段就可以了.

当我在编辑器中构建它时,U2U CAML查询构建器将返回有序的查询.

这是我如何构建和执行查询的代码片段:

String baseQuery = "<Query><Where><Eq><FieldRef Name='paApproved' /><Value Type='Boolean'>1</Value></Eq></Where><OrderBy><FieldRef Name='paState' Ascending='True' LookupValue='TRUE' /></OrderBy></Query>";

qStates.Query = baseQuery;

SPListItemCollection byState = web.Lists["paUpdates"].GetItems(qStates);
Run Code Online (Sandbox Code Playgroud)

其余的是一个for循环,它解析集合并显示它.如有必要,我可以发布.

这是CAML查询工具发出的SOAP调用,我使用wireshark从HTTP流中删除它.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 
      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
  <GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
   <listName>paUpdates</listName>
   <query>
    <Query xmlns="">
     <Where>
      <Eq>
       <FieldRef Name="paApproved" />
       <Value Type="Boolean">1</Value>
      </Eq>
     </Where>
     <OrderBy>
      <FieldRef Name="paState" Ascending="False" />
     </OrderBy>
    </Query>
   </query>
   <viewFields>
    <ViewFields xmlns="" />
   </viewFields>
   <queryOptions>
    <QueryOptions xmlns="" />
   </queryOptions>
  </GetListItems>
 </soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)

无论出于何种原因,CAML查询工具都能正常工作,我的代码却没有.谁知道为什么?提前致谢.

编辑反映我实际测试的代码.我有一些代码值不正确.

c# sharepoint caml

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

sharepoint:以编程方式将现有网站列添加到现有内容类型

var objWeb = properties.Feature.Parent as SPWeb;

SPContentType contentType = objWeb.ContentTypes["Wiki Page"];
if (!contentType.Fields.ContainsField("Keywords"))
{
    SPField field = objWeb.Fields["Keywords"];
    SPFieldLink fieldLink = new SPFieldLink(field);
    contentType.FieldLinks.Add(fieldLink);
    contentType.Update(true);
}
Run Code Online (Sandbox Code Playgroud)

我在功能激活中使用此代码将站点列"KeyWord"添加到站点内容类型"Wiki Page"我的问题是"关键字"添加到"wiki页面"但不是从现有站点列添加新站点列.我的代码有问题吗?

另外一件事,当我在office365上部署这个问题时,我的MOSS服务器上的这个代码工作得很好

c# sharepoint-2010

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

WPF ListBox ItemsSource StaticResource/Binding问题

给出以下代码:

<Window x:Class="WpfApplication76.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
    Title="Window1" Height="300" Width="300">

    <Window.Resources>
        <CollectionViewSource x:Key="myCol">
            <CollectionViewSource.Source>
                <col:ArrayList>
                    <ListBoxItem>Uno</ListBoxItem>
                    <ListBoxItem>Dos</ListBoxItem>
                    <ListBoxItem>Tres</ListBoxItem>
                </col:ArrayList>
            </CollectionViewSource.Source>
        </CollectionViewSource>
    </Window.Resources>

    <Grid>
        <ListBox ItemsSource="{StaticResource myCol}" />
        <ListBox ItemsSource="{Binding Source={StaticResource myCol}}" />
    </Grid>

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

在这个例子中,

<ListBox ItemsSource="{StaticResource myCol}" />
Run Code Online (Sandbox Code Playgroud)

给我一个错误,抱怨它无法绑定到"CollectionViewSource"对象.

但是另一个列表框:

<ListBox ItemsSource="{Binding Source={StaticResource myCol}}" />
Run Code Online (Sandbox Code Playgroud)

结合完美.

所以我的问题是为什么一个工作而另一个不工作?最后,是不是两个ItenSources都设置为相同的"CollectionViewSource"对象?

谢谢.

wpf binding wpf-controls staticresource

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

WPF Datagrid:加载时,选择当前项目(突出显示)

我有一个WPF Datagrid绑定到我的ViewModel中的一些属性

<DataGrid AutoGenerateColumns="False" Name="dataGrid" SelectionMode="Single"
          ItemsSource="{Binding ItemList}" SelectedItem="{Binding SelectedItem}">
...
</DataGrid>
Run Code Online (Sandbox Code Playgroud)

当我的窗口加载和Datagrid时,我设置了SelectedItem它并且它绑定正常但行没有突出显示.单击一行时,行突出显示并解决问题.

如何SelectedItem在加载/初始化时设置/触发DataGrid中的突出显示?

编辑:

它实际上是因为我有一个小选择单元格.它只是不会触发的突出显示的渲染.

在此输入图像描述

wpf datagrid initialization highlighting selection

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

在python中使用if语句生成器

或者如何在修改后的列表中使用if语句.

我一直在阅读StackOverflow一段时间(感谢大家).我喜欢它.我也看到你可以发一个问题并自己回答.很抱歉,如果我复制,但我没有在StackOverflow上找到这个特定的答案.


  • 如何验证元素是否在列表中但是在同一时间修改它?

我的问题:

myList = ["Foo", "Bar"]
if "foo" in myList:
  print "found!"
Run Code Online (Sandbox Code Playgroud)

由于我不知道列表中元素的情况,我想与小写列表进行比较.明显但丑陋的答案是:

myList = ["Foo", "Bar"]
lowerList = []

for item in myList:
  lowerList.append(item.lower())

if "foo" in lowerList:
  print "found!"
Run Code Online (Sandbox Code Playgroud)

我可以做得更好吗?

python if-statement list-comprehension list generator

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