小编Gor*_*ran的帖子

如何在c#comment中添加xaml代码?

/// <summary>
/// 
/// </summary>
/// <remarks
/// 
/// </remarks>
Run Code Online (Sandbox Code Playgroud)

如何在上面的注释中添加xaml代码,避免代码解析器创建不存在的链接(CTRL + Click消息)?

c# xaml xml-documentation

4
推荐指数
2
解决办法
1877
查看次数

ScrollViewer和TextBlock包装

我有以下布局(简化):

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition MaxWidth="400" />
    <ColumnDefinition />
  </Grid.ColumnDefinitions>

  <!-- Code for Column=0 -->

  <ScrollViewer Grid.Column="1">
    <Grid x:Name="layoutGrid">

      <Grid.ColumnDefinitions>
        <Grid.ColumnDefinition Width="Auto" />
        <Grid.ColumnDefinition MinWidth="100" MaxWidth="400" />
        <Grid.ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>

      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
      </Grid.RowDefinitions>


      <!-- Code for Row=0 and Row=1 -->

      <GroupBox Grid.ColumnSpan="3" Grid.Row=2>
        <TextBlock Text="{Binding ...}" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" />
      </GroupBox>
    </Grid>
  </ScrollViewer>
</Grid>
Run Code Online (Sandbox Code Playgroud)
  • 第一列应该占据所需的空间(有时它可以是100像素,有时是500).
  • 第二列应伸展到可用空间,但不超过400像素(变得难看).
  • 第三列应尽可能多地占用空间(有时可以是200像素,有时是400像素).
  • 如果在极少数情况下,layoutGrid需要的空间超过屏幕上的可用空间,则应该可以看到水平滚动条.
  • GroupBox应该始终具有所有三列的总宽度(它应该尽可能多地扩展它们的宽度).在那个空间里,文本框应该换行.GroupBox不应该伸展到屏幕上可用的整个空间.

我怎样才能在xaml中实现这一目标?似乎只要插入ScrollViewer,TextBlock就不再包装了.

wpf wpf-4.0

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

通过lambda表达式传递属性,并对其属性进行排序

我有一个ISomeType列表,其中T包含至少一个IConvertibleProperty类型的属性.例:

IConvertibleProperty
{
    string PropertyA { get; set; }
    string PropertyB { get; set; }
    // etc
}

public class SomeTypeA : ISomeType
{
    public ConvertibleProperty PropertyX { get; set; }
    // etc
}
Run Code Online (Sandbox Code Playgroud)

我需要创建一个泛型函数,我可以通过以下方式调用它:

CustomMethod(list, x => x.PropertyX);
Run Code Online (Sandbox Code Playgroud)

并且将能够在其中实现下一个排序:

protected void CustomMethod<T, TKey>(IList<T> list, Func<T, TKey> expr) where T : ISomeType where TKey : IConvertibleProperty
{
    // example of non-generic sorting (in this case expr = x.PropertyX)
    var sortedList = list.OrderBy(x => x.PropertyX.PropertyA).ThenBy(x => x.PropertyX.PropertyB).ToList();

    // rest of the …
Run Code Online (Sandbox Code Playgroud)

c# generics

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

找到范围内的值= c#中是否有这样的代码关键字?

在很多情况下我们必须做这样的事情:

if (someVariable == value1 || someVariable == value2 || someVariable == value1...)
Run Code Online (Sandbox Code Playgroud)

如果我们能够以下列方式做到这一点会不会很好:

if (someVariable in {value1, value2, value3...}
Run Code Online (Sandbox Code Playgroud)

我们做得到

int[] arr = {value1, value2, value3....};
if (arr.Contains(someVariable)) ...
Run Code Online (Sandbox Code Playgroud)

但就我而言,它仍然势不可挡.为什么没有对这种语法的支持,或者有但我不知道呢?

.net c#

0
推荐指数
2
解决办法
103
查看次数

c#null-coalescing operator(??)编译器代码优化

我对下一种情况下的编译器效率感到好奇:

double total = list.Sum(x => x.Value) ?? 0;
Run Code Online (Sandbox Code Playgroud)

问:编译器会生成一次或两次执行Sum函数的代码吗?

它可以生成如下内容:

double total = list.Sum(x => x.Value) == null ? 0 : (double)list.Sum(x => x.Value);
Run Code Online (Sandbox Code Playgroud)

要么

double temp = list.Sum(x => x.Value);
total = temp == null ? 0 : (double)temp;
Run Code Online (Sandbox Code Playgroud)

c# c#-4.0

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

标签 统计

c# ×4

.net ×1

c#-4.0 ×1

generics ×1

wpf ×1

wpf-4.0 ×1

xaml ×1

xml-documentation ×1