小编Won*_*ane的帖子

如何阻止Skype使用HTTP或HTTPS端口80和443?

我在我的Windows 7机器上安装了Apache Web服务器,因为Skype.exe已经在使用HTTP端口80和HTTPS端口443,所以我无法启动它.

Skype端口

我需要Apache和Skype在同一台机器上共存.如何配置Apache以使用其他端口,或阻止Skype在这些端口上侦听?

port webserver skype

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

在foreach循环中启动任务使用最后一项的值

我正在尝试使用新任务,但发生了一些我不明白的事情.

首先,代码非常简单.我传入一些图像文件的路径列表,并尝试添加一个任务来处理它们中的每一个:

public Boolean AddPictures(IList<string> paths)
{
    Boolean result = (paths.Count > 0);
    List<Task> tasks = new List<Task>(paths.Count);

    foreach (string path in paths)
    {
        var task = Task.Factory.StartNew(() =>
            {
                Boolean taskResult = ProcessPicture(path);
                return taskResult;
            });
        task.ContinueWith(t => result &= t.Result);
        tasks.Add(task);
    }

    Task.WaitAll(tasks.ToArray());

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

我发现,如果我让它运行,例如,单元测试中的3个路径列表,则所有三个任务都使用提供列表中的最后一个路径.如果我单步执行(并减慢循环的处理速度),则使用循环中的每个路径.

有人可以解释一下发生了什么,为什么?可能的解决方法?

c# multithreading task-parallel-library

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

ItemsControl ItemTemplate绑定

在WPF4.0中,我有一个类包含其他类类型作为属性(组合多个数据类型用于显示).就像是:

public partial class Owner
{
     public string OwnerName { get; set; }
     public int    OwnerId   { get; set; }
}

partial class ForDisplay
{
    public Owner OwnerData { get; set; }
    public int Credit { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

在我的窗口中,我有一个带有以下内容的ItemsControl(为了清晰起见而剪裁):

<ItemsControl ItemsSource={Binding}>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
          <local:MyDisplayControl 
                OwnerName={Binding OwnerData.OwnerName}
                Credit={Binding Credit} />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)

然后我得到的数据层显示信息的集合,并设置DataContextItemsControl这个集合."Credit"属性正确显示,但OwnerName属性不正确.相反,我得到一个绑定错误:

错误40:BindingExpression路径错误:'对象'上找不到'OwnerName'属性''ForDisplay'(HashCode = 449124874)'.BindingExpression:路径= OWNERNAME; DataItem ='ForDisplay'(HashCode = 449124874); target元素是'TextBlock'(Name = txtOwnerName'); target属性是'Text'(类型'String')

我不明白为什么这会尝试在ForDisplay类中查找OwnerName属性,而不是在ForDisplay OwnerData属性的Owner类中查找.

编辑 它似乎与使用自定义控件有关.如果我将相同的属性绑定到a TextBlock,它们可以正常工作.

<ItemsControl ItemsSource={Binding}>
    <ItemsControl.ItemTemplate> …
Run Code Online (Sandbox Code Playgroud)

wpf binding .net-4.0 itemtemplate itemscontrol

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

在保留元数据的同时调整大小并保存图像

我正在尝试调整大小并保存图像,这非常简单(例如,请参阅此示例 外部示例不再有效).

但是,使用此代码会从图像中剥离元数据信息.我似乎无法弄清楚如何保留jpeg图像的元数据.

**编辑:示例代码**

public static void ResizeMethodThree(string sourceFile, string targetFile)
{
    byte[] baSource = File.ReadAllBytes(sourceFile);

    PropertyItem[] propertyItems = new Bitmap(sourceFile).PropertyItems;

    using (Stream streamPhoto = new MemoryStream(baSource))
    {
        BitmapFrame bfPhoto = ReadBitmapFrame(streamPhoto);
        BitmapMetadata metaData = (BitmapMetadata)bfPhoto.Metadata;
        int nNewPictureSize = 200;
        int nWidth = 0;
        int nHeight = 0;

        if (bfPhoto.Width > bfPhoto.Height)
        {
            nWidth = nNewPictureSize;
            nHeight = (int)(bfPhoto.Height * nNewPictureSize / bfPhoto.Width);
        }
        else
        {
            nHeight = nNewPictureSize;
            nWidth = (int)(bfPhoto.Width * nNewPictureSize / bfPhoto.Height);
        }        

        BitmapFrame …
Run Code Online (Sandbox Code Playgroud)

c# wpf metadata image-processing image-resizing

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

默认情况下,是否可以使Visual Studio折叠摘要部分

是否可以让Visual Studio默认折叠方法和类的摘要部分?或者是否有命令折叠所有摘要部分而不折叠方法本身?

我在下面提供了摘要部分示例.

倒塌的例子
在此输入图像描述

扩展示例
在此输入图像描述

c# visual-studio-2010

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

属性继承与反思

我创建了一个自定义属性来装饰我想在运行时查询的许多类:

[AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public class ExampleAttribute : Attribute
{
    public ExampleAttribute(string name)
    {
        this.Name = name;
    }

    public string Name
    {
        get;
        private set;
    }
}
Run Code Online (Sandbox Code Playgroud)

这些类中的每一个都派生自一个抽象基类:

[Example("BaseExample")]
public abstract class ExampleContentControl : UserControl
{
    // class contents here
}

public class DerivedControl : ExampleContentControl
{
    // class contents here
}
Run Code Online (Sandbox Code Playgroud)

我是否需要将此属性放在每个派生类上,即使我将其添加到基类中?该属性被标记为可继承,但是当我执行查询时,我只看到基类而不是派生类.

另一个线程:

var typesWithMyAttribute = 
    from a in AppDomain.CurrentDomain.GetAssemblies()
    from t in a.GetTypes()
    let attributes = t.GetCustomAttributes(typeof(ExampleAttribute), true)
    where attributes != null && attributes.Length > 0 …
Run Code Online (Sandbox Code Playgroud)

c# reflection inheritance attributes custom-attributes

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

自定义按钮的前景色(ControlPresenter)

我试图在App.xaml中定义一个全局按钮样式,它主要按照我的预期工作.但是,我只是想不通如何让Foreground正常工作.无论我做什么,我都会得到默认TextBlock的样式(将颜色设置为白色).

    <Style TargetType="{x:Type Button}">
        <Setter Property="Margin" Value="3, 5" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="FocusVisualStyle" 
                Value="{StaticResource ButtonFocusVisual}" />
        <Setter Property="Foreground" Value="Red" />
        <Setter Property="Padding" Value="5" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid x:Name="gridMainButton"
                          RenderTransformOrigin="0.5, 0.5">
                        <Grid.RenderTransform>
                            <ScaleTransform x:Name="scaleTransform" 
                                            CenterX="0.5"
                                            CenterY="0.5" />
                        </Grid.RenderTransform>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates" >
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver" />
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <DoubleAnimation
                                              Storyboard.TargetName="scaleTransform"
                                              Storyboard.TargetProperty="ScaleX"
                                              Duration="0"
                                              To="0.85" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Ellipse x:Name="ellipse"
                                 HorizontalAlignment="Stretch"
                                 VerticalAlignment="Stretch"
                                 StrokeThickness="2"
                                 Stroke="{StaticResource standardBackground}"
                                 Fill="{StaticResource standardBackground}" />
                        <ContentPresenter HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          Margin="4, 8"/> …
Run Code Online (Sandbox Code Playgroud)

wpf controls controltemplate

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

防止基类的序列化

我觉得我应该知道这一点,但出于某种原因....

序列化从(可能是抽象的)基类派生的类的首选方法是什么,而不必一直序列化备份树?例如,您可能无法控制从中派生的类,但希望使用序列化来克隆您的对象(仅限您的对象,而不是基础).

例如:

// This is a base class that is outside my control, which derives from
// some other base class that I know "nothing" about
public abstract class SomeBaseClass : SomeOtherBaseClass
{
    private string mBaseProperty = "Base Property";
    public string BaseProperty
    {
        get { return mBaseProperty; }
        set { mBaseProperty = value; }
    }
}

// This is the class that I do control
[Serializable()]
private class MyDerivedClass : SomeBassClass
{
    // Assume normal constructors, etc.

    // Here …
Run Code Online (Sandbox Code Playgroud)

c# serialization

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

获得实际的视图高度

简单的问题,也许是令人沮丧的复杂但希望简单的答案?

获取其大小设置为FILL_PARENT的元素的实际高度的"最佳实践"是什么?

size android android-layout

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

禁用将项添加到集合

我确信这是一个"简单"的答案,但目前它逃脱了我.

在MVVM应用程序中,我有一个ObservableCollection属性,用于在视图上显示一些元素集.

private readonly ObservableCollection<MyType> mMyCollection = 
    new ObservableCollection<MyType>();
public ObservableCollection<MyType> MyCollection
{
    get { return mMyCollection; }
}
Run Code Online (Sandbox Code Playgroud)

我想限制此集合的使用者只需使用该属性添加到集合(即我想从视图中阻止这种情况):

   viewModel.MyCollection.Add(newThing);   // want to prevent this!
Run Code Online (Sandbox Code Playgroud)

相反,我想强制使用一个方法来添加项目,因为可能有另一个线程使用该集合,我不想在该线程处理它时修改该集合.

public void AddToMyCollection(MyType newItem)
{
    // Do some thread/task stuff here
}
Run Code Online (Sandbox Code Playgroud)

c# collections wpf mvvm

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