小编DrK*_*och的帖子

具有最小约束的GridSplitter

我想要一个有两行的网格布局和它们之间的分割器.行的最小高度应为80像素.

这段代码效果很好:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" MinHeight="80" />
        <RowDefinition Height="5" />
        <RowDefinition Height="*" MinHeight="80" />
    </Grid.RowDefinitions>
    <TextBlock Grid.Row="0" Text="{Binding Path=ActualHeight, RelativeSource={RelativeSource Self}}" />
    <GridSplitter Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Red" />
    <TextBlock Grid.Row="2" Text="{Binding Path=ActualHeight, RelativeSource={RelativeSource Self}}" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

但我希望顶行有一个自动高度,直到用户使用拆分器手动更改它.所以我把代码更改为:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" MinHeight="80" />
        <RowDefinition Height="5" />
        <RowDefinition Height="*" MinHeight="80" />
    </Grid.RowDefinitions>
    <TextBlock Grid.Row="0" Text="{Binding Path=ActualHeight, RelativeSource={RelativeSource Self}}" />
    <GridSplitter Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Red" />
    <TextBlock Grid.Row="2" Text="{Binding Path=ActualHeight, RelativeSource={RelativeSource Self}}" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

而且有一个问题.Splitter仍然满足行约束,但如果我将分割器拖得太低,它会无限地开始增加顶行的高度.这导致底行完全低于窗口的底部边框.

我在GridSplitter代码上做了一些Reflector,看看如果行有Auto或Star高度它会使用不同的逻辑.

任何建议如何"修复"它?

wpf xaml gridsplitter

15
推荐指数
2
解决办法
8216
查看次数

DateTime格式与文化不匹配

我有一个Windows Server 2008 R2系统配置了默认的区域设置(没有覆盖格式或任何东西),它设置为en-US.

当我询问以下内容时: System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat

它将DateSeparator列为-(破折号)而不是/(斜杠).所以DateTime.Now.ToString()看起来像这样:

01-30-2015.

另外,CurrentThread.CurrentCulture.ToString()="en-US"

我完全不知道这是怎么可能的,但更重要的是,我想知道.NET是否有某种类型的语言环境覆盖,可以通过某种方式进行配置?

系统区域和语言设置是正常的,尚未更改.非常感谢任何帮助,谢谢.

这是诊断信息的代码.它是在asp.net页面上的asp.net中运行的.

Current Date Time: <%= DateTime.Now.ToString() %>
Current Short Date: <%= DateTime.Now.ToShortDateString() %>
Current Culture: <%= System.Threading.Thread.CurrentThread.CurrentCulture.ToString() %>
Current UI Culture: <%= System.Threading.Thread.CurrentUICulture.ToString() %>

DateTimeFormatInfo invariant = CultureInfo.InvariantCulture.DateTimeForamat;
DateTimeFormatInfo uiThread = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat;
DateTimeFormatInfo thread = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat;

Type type = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.GetType();
foreach( var prop in type.GetProperties()) {
  <%= prop.Name %> 
  <%= prop.GetValue(invariant, null) %> <br/>
  <%= prop.GetValue(uiThread, null) %> <br/>
  <%= prop.GetValue(thread, null) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net datetime locale

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

将Dictionary转换为HashEntry

我试图使用hashSet方法,它需要HashEntry []数组.

HashSet(RedisKey key, HashEntry[] hashFields, CommandFlags flags = CommandFlags.None);
Run Code Online (Sandbox Code Playgroud)

我试图这样做,但这显然不起作用......

我有字典值

  HashEntry[] hash = new HashEntry[value.Count]();
  int index = 0;
  foreach (var item in value)
  {
        hash[index].Name = item.Key;
        hash[index].Value = item.Value;
        index++;
  }
Run Code Online (Sandbox Code Playgroud)

c# redis

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

制作字典的深层副本

我有一个名为 baseDictionary 的字典。键是一个字符串,值是名为 myData 的类的属性。具体来说,这些属性是:“年龄”(作为 int)、“国籍”(作为字符串)和“收入”(作为 double)。

因此,baseDictionary 有一些字符串作为键,每个键都有一系列与特定人员相关的属性。我想在某个时候制作这本字典的深层副本,以便我可以使用这个新副本而不修改原始字典的内容。我在 stackoverflow 中找到了答案,其中建议使用以下代码来执行此深度复制:

public static Dictionary<TKey, TValue>
     CloneDictionaryCloningValues<TKey, TValue>(
         Dictionary<TKey, TValue> original) where TValue : ICloneable
{
    Dictionary<TKey, TValue> ret = new Dictionary<TKey, TValue>(
         original.Count, original.Comparer);

    foreach (KeyValuePair<TKey, TValue> entry in original)
    {
        ret.Add(entry.Key, (TValue) entry.Value.Clone());
    }
    return ret;
}
Run Code Online (Sandbox Code Playgroud)

问题是我不明白应该如何修改它以使其与我的字典一起使用。例如我尝试过:

public static Dictionary<string, myData> CloneDictionaryCloningValues<TKey, TValue>
                    (Dictionary<string, myData> original) where TValue : ICloneable
    {
        Dictionary<string, myData> ret = new Dictionary<string, myData>(original.Count,
                                                                original.Comparer);
        foreach (KeyValuePair<string, myData> entry in original)
        {
            ret.Add(entry.Key, (myData)entry.Value.Clone()); …
Run Code Online (Sandbox Code Playgroud)

c# dictionary copy

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

调用存储在字典中的方法

我正在看这里发布的例子:从字典中调用方法,是否有人可以提出更真实的东西?

调用一个具有更多复杂参数的方法,我试着在这里调整示例,但很抱歉,没有足够的经验.

这是发布但是如何调用这样的方法?

private static void Method1(string[] curr, string[] prev, int counter)
{
    var a1 = curr[5];
    Console.WriteLine(a1);
}
Run Code Online (Sandbox Code Playgroud)

对不起,如果问题有点"tony the pony":-)

上面的贴子示例如下

    private static void Method1(int x)
    {
        Console.WriteLine(x);
    }

    private static void Method2(int x)
    {
    }

    private static void Method3(int x)
    {
    }

    static void Main(string[] args)
    {
        Dictionary<int, Action<int>> methods = new Dictionary<int, Action<int>>();
        methods.Add(1, Method1);
        methods.Add(2,  Method2);
        methods.Add(3, Method3);

        (methods[1])(1);
    }
Run Code Online (Sandbox Code Playgroud)

c# dictionary

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

有没有办法让房产设定其支持价值?

我有一个属性,我希望它在设置时设置另一个属性.例如:

    private double Bpm
    {
        set
        {
            <myself> = value;
            _bps = <myself> / 60;
        }
        get
        {
            return <myself>;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我实际做的是以下,因为我找不到另一种方式:

    private double _bpm;
    private double _bps;

    private double Bpm
    {
        set
        {
            _bpm = value;
            _bps = _bpm / 60;
        }
        get
        {
            return _bpm;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我发现它不优雅,有两个私人成员Bpm_bpm.我也可以有一个SetBpm方法,但我想知道这是否可以用属性实现.

c# properties

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

列表中的字符串比较

我有两个字符串列表

l1 = {abc;xyz}  
l2 = {lmn,xyz,abc}  
Run Code Online (Sandbox Code Playgroud)

我想迭代这两个列表,看看l2是否包含l1中的所有元素,以及l1是否包含l2中的所有元素.
字符串的顺序无关紧要.请注意,字符串具有分隔符";"
我正在使用这两个for循环,但第二个for循环使索引超出范围.有一个更好的方法吗?

for (int i = 0; i < l1.Count; i++)
{
     if (l1[i].Contains(l2[i])) {
          Console.WriteLine("value {0} present in l1", l2[i]);
     }
     else {
          Console.WriteLine("value {0} is not present in l1", l2[i]);
     }
}

for (int i = 0; i < l2.Count; i++)
{
    if (l2[i].Contains(l1[i]))  {
        Console.WriteLine("value {0} present in l2", l2[i]);
    }
    else {
        Console.WriteLine("value {0} is not present in l2", l2[i]);
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c#

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

Gtk打开默认文件管理器文件夹

我需要使用gtk和C打开用户系统的默认文件管理器(不是对话框,而是系统使用的文件管理器).

这意味着,当用户选择目录时,文件管理器将打开而不是对话框.有没有办法实现这个目标?

c gtk2

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

当“启用 32 位应用程序”设置为 true 时无法访问服务

在开发服务器上我使用 IIS Veresion 7.5.7600.16385

以及为 .Net 4.5.1 编译的服务,任何 CPU

该服务在开发服务器 (Win Server 2008 R2) 上运行良好。

但是在客户端的生产服务器上,我遇到了奇怪的问题:

(相同的 IIS 版本,相同的操作系统版本)

一旦我设置了“启用 32 位应用程序”,就无法在浏览器中访问该服务的URL。(页面不可用)

(我需要 32Bit 模式,因为该服务使用了一些旧的 COM 组件)

什么可能导致这些问题?

任何想法,提示,建议?


编辑

更多细节:

“IIS 工作进程”作为“w3wp.exe *32”运行

在同一个应用程序池中有一个 ClickOnce 安装,其行为相同:在 64 位下工作正常,如果 32Bit 设置为 true,则无法访问。

事实上,这个 32Bit App-Pool 的所有页面都产生了相同的行为 (HTTP 500) 页面未找到。

web-services windows-server-2008 iis-7.5 .net-4.5

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

将int转换为char C.

我试图把INT喜欢72, 101, 108'72', '101', '108'.

原始程序是我读取字符串"Hello\n"为例,然后获取每个字符的ASCII值,然后将这些int放入char数组中.

我试过了:

int a = 72;
char b = (char)a; 
Run Code Online (Sandbox Code Playgroud)

但是这会将int从ASCII转换回字符.

我也尝试过:

int a = 72;
char b = a + '0';
Run Code Online (Sandbox Code Playgroud)

但这根本不起作用.

这就是我所拥有的:

char buff[128];
strcpy(buff, "Hello\n");

char tmp[128];
bzero(tmp, 128); // initialize array

int n = 0;
while(buff[n] != '\n') {
   int ascii = (int)buff[n];
   en[n] = (char)ascii; // RIGHT HERE
   n++;
}
strcat(tmp, "\n");

fprintf(stdout,"%s", tmp);
Run Code Online (Sandbox Code Playgroud)

c int char

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

查找包含给定时间点的间隔的最快方法

我需要创建基于时间的"计划结构",使用以下方法:

Void  addTask(DateTime startTime, int durationInMinutes, TaskObject myObj)
{
   // add TaskObject to calendar structure
}
List<TaskObject> getRunningTasks (DateTime startTime, DateTime endTime)
{
  //this procedure have to efficiently return list of running tasks in specified time frame
}
List<TaskObject> getRunningTasks (DateTime exactTime)
{
    return getRunningTaks(exactTime,exactTime);
}
Run Code Online (Sandbox Code Playgroud)

我有大约60k个TaskObjects需要计算,需要在几小时和几分钟内重新计算(getRunningTasks将被调用大约400k次)

现在我使用:

public Dictionary<long, Dictionary<int, Dictionary<int, List< TaskObject>>>> scheduleTable;
Run Code Online (Sandbox Code Playgroud)

scheduleTable [dayInTicks] [小时] [分钟]

我将所有匹配的任务添加到每个小时和分钟,在哪里安排它们.

来自DrKoch的想法

    public class TaskList
    {
        private SortedDictionary<DateTime, TaskObject> startTimes;
        private SortedDictionary<DateTime, TaskObject> endTimes;
        private SortedSet<DateTime> startTimeIndexes;
        private SortedSet<DateTime> endTimeIndexes;
        public …
Run Code Online (Sandbox Code Playgroud)

c# algorithm datetime intervals

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