小编Jak*_*mpl的帖子

Dependency属性更改了回调 - 多次触发

我想听听DependencyProperty的变化.此代码有效,但每次使用CustomControl重新加载页面后都会调用多次回调方法...

public partial class CustomControl : UserControl
{
    public CustomControl()
    {
        InitializeComponent();
    }

    public bool IsOpen
    {
        get { return (bool)GetValue(IsOpenProperty); }
        set { SetValue(IsOpenProperty, value); }
    }

    public static readonly DependencyProperty IsOpenProperty =
        DependencyProperty.Register("IsOpen", typeof(bool), typeof(CustomControl), new PropertyMetadata(IsOpenPropertyChangedCallback));

    private static void IsOpenPropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        Debug.WriteLine("Fire!");
    }
}
Run Code Online (Sandbox Code Playgroud)

更新

视图模型

private bool _isOpen;
public bool IsOpen
{
    get { return this._isOpen; }
    set { this.Set(() => this.IsOpen, ref this._isOpen, value); } // MVVM Light Toolkit
}
Run Code Online (Sandbox Code Playgroud)

视图

<local:CustomControl …
Run Code Online (Sandbox Code Playgroud)

c# windows-phone-8

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

UWP应用程序的Debug.Listeners

是否有可能将所有内容转发Debug.WriteLine到UWP应用程序中的文件?

Debug.Listeners遗憾的是,在UWP应用程序中没有.然而,我发现NuGet包System.Diagnostics.TraceSource这使得使用TraceTrace.Listeners在UWP.因此,我认为可能也可以这样做,Debug但我没有找到任何合适的包或方法在UWP中工作.

c# debugging win-universal-app uwp

6
推荐指数
0
解决办法
506
查看次数

如何将带有 HTML 标签的文本拆分为数组

我有非常简单的 HTML 文本(只有<b>标签),例如

Lorem Ipsum is <b>simply dummy</b> text of the printing and <b>typesetting industry</b>

我想将文本拆分为这样的数组:

[0] - Lorem Ipsum is 
[1] - <b>simply dummy</b>
[2] - text of the printing and
[3] - <b>typesetting industry</b>
Run Code Online (Sandbox Code Playgroud)

HTML 标签内的文本必须与另一个文本分开。有什么简单的解决方案吗?

谢谢

c# windows-8.1 windows-phone-8.1 win-universal-app

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

通过 HttpClient 发送大文件

我需要通过 HTTP 协议上传大文件(~200MB)。我想避免将文件加载到内存中并想直接发送它们。

多亏了这篇文章,我才能用HttpWebRequest.

HttpWebRequest requestToServer = (HttpWebRequest)WebRequest.Create("....");

requestToServer.AllowWriteStreamBuffering = false;
requestToServer.Method = WebRequestMethods.Http.Post;
requestToServer.ContentType = "multipart/form-data; boundary=" + boundaryString;
requestToServer.KeepAlive = false;
requestToServer.ContentLength = ......;

using (Stream stream = requestToServer.GetRequestStream())
{
    // write boundary string, Content-Disposition etc.
    // copy file to stream
    using (var fileStream = new FileStream("...", FileMode.Open, FileAccess.Read))
    {
        fileStream.CopyTo(stream);
    }

    // add some other file(s)
}
Run Code Online (Sandbox Code Playgroud)

但是,我想通过HttpClient. 我找到了描述使用 of 的文章HttpCompletionOption.ResponseHeadersRead我尝试了类似的方法,但不幸的是它不起作用。

WebRequestHandler handler = new WebRequestHandler();

using …
Run Code Online (Sandbox Code Playgroud)

.net c# console-application

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

UWP 项目中的条件包引用

我想使用一个 NuGet 包仅用于调试配置。如果我有一个针对 Creators Update (15063) 的 UWP 项目,我发现可以在 Visual Studio 2017 中执行此操作。

<PackageReference Include="Newtonsoft.json" Version="9.0.1" Condition="'$(Configuration)' == 'Debug'" />
Run Code Online (Sandbox Code Playgroud)

但该包仍然存在用于发布配置。

c# nuget uwp visual-studio-2017

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