小编Pol*_*ris的帖子

如何将MemoryStream写入byte []

可能重复:
从流创建字节数组

我正在尝试在内存中创建文本文件并编写它byte[].我怎样才能做到这一点?

public byte[] GetBytes()
{
    MemoryStream fs = new MemoryStream();
    TextWriter tx = new StreamWriter(fs);

    tx.WriteLine("1111");
    tx.WriteLine("2222");
    tx.WriteLine("3333");

    tx.Flush();
    fs.Flush();

    byte[] bytes = new byte[fs.Length];
    fs.Read(bytes,0,fs.Length);

    return bytes;
}
Run Code Online (Sandbox Code Playgroud)

但由于数据长度,它不起作用

c# stream

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

从基类获取Child类

在C#中是否可以从基类中获取子类的类型?

c# class

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

如何在后台线程中创建WPF控件?

我有创建后台线程的方法来做一些动作.在这个后台线程中我创建了对象.但是在运行时创建时这个对象给了我一个例外:

调用线程必须是STA,因为许多UI组件都需要这个.

我知道我必须使用Dispatcher来反映UI的内容.但在这种情况下,我只是创建一个对象,而不是用UI迭代.这是我的代码:

    public void SomeMethod()
      {
         BackgroundWorker worker = new BackgroundWorker();
         worker.DoWork += new DoWorkEventHandler(Background_Method);
         worker.RunWorkerAsync();
      }

   void Background_Method(object sender, DoWorkEventArgs e)
      {
         TreeView tv = new TreeView();
      }
Run Code Online (Sandbox Code Playgroud)

如何在后台线程中创建对象?

我使用WPF应用程序

c# wpf multithreading backgroundworker

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

ListBox SelectedItems绑定

我想将Listbox selectedItems绑定到数组.但.NET在运行时抛出异常.

d.SetBinding(ListBox.SelectedItemsProperty, new Binding { Source = SomeArray });
Run Code Online (Sandbox Code Playgroud)

dXAML中的一些ListBox 在哪里.

例外:

所选项目无法绑定.

为什么?

c# data-binding wpf

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

使用TemplateBinding更新源代码

我将这种风格用于所有标签

    <Style TargetType="Label" x:Key="LabelStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Label">
                    <StackPanel Orientation="Horizontal"  >
                        <TextBox Loaded="MyTextBlock_Loaded" x:Name="EditControl" Visibility="Collapsed" Text="{TemplateBinding Tag}" />
                        <Label Content="{TemplateBinding Content}" Grid.Column="1" Grid.Row="1">
                        </Label>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
Run Code Online (Sandbox Code Playgroud)

和我的样品标签

<Label Grid.Column="0" Grid.Row="0" Content="Photo" Style="{StaticResource LabelStyle}" Tag="{Binding fieldsCode.firstName, UpdateSourceTrigger=PropertyChanged}"/>
Run Code Online (Sandbox Code Playgroud)

但我觉得TemplateBiding不支持更新属性.怎么能解决这个问题

data-binding wpf templatebinding

8
推荐指数
2
解决办法
6801
查看次数

如何处理MVVM中的事件

我是MVVM的新手.我只是学习这种模式,并希望在我的项目中使用它.我已经理解了这种模式的工作原理,并学会了如何使用命令.但我有问题如何处理另一个控件的事件,例如ListBox SelectionChanged事件.ListBox没有Command属性

c# wpf events mvvm

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

'%'运算符是什么意思?

我有下一个代码

int a,b,c;
b=1;
c=36;
a=b%c;
Run Code Online (Sandbox Code Playgroud)

"%"运算符是什么意思?

c# operators

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

具有文件系统依赖性的TDD

我有一个集成测试LoadFile_DataLoaded_Successfully().我想将它重构为单元测试以破坏与filesytem的依赖关系.

PS我是TDD的新手:

这是我的生产类:

public class LocalizationData
{
    private bool IsValidFileName(string fileName)
    {
        if (fileName.ToLower().EndsWith("xml"))
        {
            return true;
        }
        return false;
    }

    public XmlDataProvider LoadFile(string fileName)
    {
        if (IsValidFileName(fileName))
        {
            XmlDataProvider provider = 
                            new XmlDataProvider
                                 {
                                      IsAsynchronous = false,
                                      Source = new Uri(fileName, UriKind.Absolute)
                                 };

            return provider;
        }
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

和我的考试班(Nunit)

[TestFixture]
class LocalizationDataTest
{
    [Test]
    public void LoadFile_DataLoaded_Successfully()
    {
        var data = new LocalizationData();
        string fileName = "d:/azeri.xml";
        XmlDataProvider result = data.LoadFile(fileName);
        Assert.IsNotNull(result);
        Assert.That(result.Document, Is.Not.Null);
    } …
Run Code Online (Sandbox Code Playgroud)

c# tdd nunit rhino-mocks

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

开源 twain 库

你能建议我用纯好的 API 扫描开源 twain 库吗?

c# wpf

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

C#中的动态类创建

是否有可能在运行时从DataTable创建一个类,其中ColumnName将是动态类属性?

c# class dynamic

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