小编Lan*_*nce的帖子

如何将Indexed属性绑定到WPF中的控件

给定一个类ThisClassShouldBeTheDataContext的实例作为视图的Datacontext

class ThisClassShouldBeTheDataContext
{
  public Contacts Contacts {get;set;}
}

class Contacts
{
  public IEnumerable<Person> Persons {get;set;}
  public Person this[string Name]
  {
    get 
    {
      var p = from i in Persons where i.Name = Name select i;
      return p.First();
    }    
  }
}

class Person
{
  public string Name {get;set;}
  public string PhoneNumber {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

如何绑定Contact["John"].PhoneNumber到文本框?

<TextBox Text="{Binding ?????}" />
Run Code Online (Sandbox Code Playgroud)

wpf xaml binding indexer properties

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

我怎么知道属性是否是泛型集合

我需要知道类中的属性类型是否是使用PropertyInfo类的泛型集合(List,ObservableCollection).

foreach (PropertyInfo p in (o.GetType()).GetProperties())
{
    if(p is Collection<T> ????? )

}
Run Code Online (Sandbox Code Playgroud)

c# generics collections propertyinfo

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

如何将工作项与TFS中的先前签入相关联

我在TFS中签入了我的代码,但我忘了关联一个工作项.我试图去登记入住历史并打开登记入住变更集详细信息,但是当我点击工作项目按钮时,它表示没有关联的工作项,并且它没有给我一个关联的选项.

tfs visual-studio-2008

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

你怎么调试这个错误?无法启动<service name>服务.该服务未报告错误

该服务无法启动.该服务未报告错误.

每当我在命令行中安装Windows服务项目时,我都会遇到此错误.确实,我的代码中存在错误,但如何通过此类错误消息找到该错误?

installer windows-services

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

如果我在属性中有验证属性,为什么Validator.TryValidateObject不验证类?

我创建了一个针对类的自定义ValidationAttribute.每当我尝试调用Validator.TryValidateObject时,这都会正确验证.但是当我在类中的属性中有其他ValidationAttribute时,验证结果不包含类级别验证的结果.

这是一个示例代码:

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class IsHelloWorldAttribute : ValidationAttribute
{
    public object _typeId = new object();
    public string FirstProperty { get; set; }
    public string SecondProperty { get; set; }

    public IsHelloWorldAttribute(string firstProperty, string secondProperty)
    {
        this.FirstProperty = firstProperty;
        this.SecondProperty = secondProperty; 
    }

    public override bool IsValid(object value)
    {
        PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value);
        string str1 = properties.Find(FirstProperty, true).GetValue(value) as string;
        string str2 = properties.Find(SecondProperty, true).GetValue(value) as string;

        if (string.Format("{0}{1}", str1,str2) == "HelloWorld")
            return true;
        return …
Run Code Online (Sandbox Code Playgroud)

c# validation annotations validationattribute

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

如何在代码中访问C#性能计数器?

我想在我的程序中使用性能计数器输出.如何在不使用perfmon.exe的情况下访问代码中的性能计数器.我想创建自己的性能计数器应用程序.

c# performance counter performancecounter

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

如何将 resx 添加为 .NET 标准项目的链接?

我有一个来自 .NET 3.5 项目的 resx 文件。我想在 .NET 标准 1.4 项目上使用相同的文件,以便我可以将 .NET 标准 dll 引用到 UWP 和 .NET 4.6 项目。

因此,我将 Strings.resx 和 Strings.Designer.cs 添加为 .NET 标准项目的链接,但是当我右键单击 resx 文件并“运行自定义工具”时,它不会生成 Designer.cs 文件。

这是项目文件的内容:

  <ItemGroup>
    <Compile Include="..\WindowsFormsApp2\Strings.Designer.cs" Link="Strings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Strings.resx</DependentUpon>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Include="..\WindowsFormsApp2\Strings.resx" Link="Strings.resx">
      <Generator>PublicResXFileCodeGenerator</Generator>
      <LastGenOutput>Strings.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我正在使用 Visual Studio 2017 Pro。

resx visual-studio .net-standard .net-standard-1.4

5
推荐指数
0
解决办法
1381
查看次数

如何在协奏曲中使用协程,以便我的代码可以像同步一样编写?

这是来自developer.android.com的示例

class MainActivity : AppCompatActivity() {

lateinit var textView:TextView
lateinit var button:Button

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    textView = findViewById(R.id.textView)
    button = findViewById(R.id.button)

    button.setOnClickListener({
        getData()
    })
}

fun getData(){
    val queue = Volley.newRequestQueue(this)
    val url = "http://www.google.com/"

    val stringRequest = StringRequest(Request.Method.GET, url,
        Response.Listener<String> { response ->             
            textView.text = "Response is: ${response.substring(0, 500)}"
        },
        Response.ErrorListener { textView.text = "Something went wrong!" })

    queue.add(stringRequest)
}
}
Run Code Online (Sandbox Code Playgroud)

我如何利用协程,以便以这种方式编写代码:

val data = getData()
textView.text = data
Run Code Online (Sandbox Code Playgroud)

coroutine kotlin android-volley

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

使用例如 android:colorAccent 和 colorAccent 属性有什么区别?

如果我使用有什么区别

<item name="colorAccent">@color/accent</item>
Run Code Online (Sandbox Code Playgroud)

或者

<item name="android:colorAccent">@color/accent</item>
Run Code Online (Sandbox Code Playgroud)

?

当我在我的主题上使用它时,第一个对我有用。它改变了我的进度条的默认颜色。

android themes colors

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

Retrofit 不调用失败,response.code() 为 400

我确信我在这里所做的事情有问题。即使我得到的代码是 400,Retrofit 也不会失败。

        AuthenticationService authService = retrofit.create(AuthenticationService.class);
        Call<ValidateTokenResponseMessage> request = authService.validateToken(token);
        request.enqueue(new Callback<ValidateTokenResponseMessage>() {
            @Override
            public void onResponse(Call<ValidateTokenResponseMessage> call, retrofit2.Response<ValidateTokenResponseMessage> response) {
            // When I try to put a breakpoint here I can see that response.code() is 400. 
                ValidateTokenResponseMessage body = response.body();
                if (!body.getValidToken()) {
                    // do success 
                }
            }

            @Override
            public void onFailure(Call<ValidateTokenResponseMessage> call, Throwable t) {
                // do failure
            }
        });
Run Code Online (Sandbox Code Playgroud)

java android retrofit

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

如何在vim中自动匹配qoutes,doubleqoutes括号括号和大括号?

我开始在日常编码中使用vim.在我探索的过程中,我发现了使用*map.所以我决定将以下映射添加到我的.vimrc文件中.

inoremap ' ''<left> 
inoremap " ""<left> 
imap ( ()<left>
imap { {}<left>
imap [ []<left>
imap < <><left>
Run Code Online (Sandbox Code Playgroud)

我的想法是匹配每个',',(,{,[,<与其结束等效.这个问题是,即使我在插入模式下粘贴,映射仍然有效.

// Pasting this 
()=>{ console.log("Hello World"); }

//Will result to something like this
())=>{} console.log())""Hello World"");}
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能防止这种情况发生?

mapping vim

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

禁用右键单击浏览器的后退和前进按钮

有没有办法使用javascript或silverlight禁用右键单击浏览器的后退和前进按钮?当您右键单击按钮时,我不希望用户访问通过上下文菜单显示的历史列表.我只希望用户能够左键单击后退和前进按钮进行导航.

javascript browser navigation browser-history

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