为什么C#允许代码块前没有声明(例如if
,else
,for
,while
)?
void Main()
{
{ // any sense in this?
Console.Write("foo");
}
}
Run Code Online (Sandbox Code Playgroud) 我想要一个有两行的网格布局和它们之间的分割器.行的最小高度应为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高度它会使用不同的逻辑.
任何建议如何"修复"它?
我可以检测(使用roslyn)x
lambda体中的引用是对外部变量的闭包x
,而不是lambda本身的局部变量吗?
var x = "foo";
var a = string[0];
a.Any(i => i == x);
Run Code Online (Sandbox Code Playgroud) 如何在xaml字符串中使用{符号?例如:
<TextBlock Text="{0}"/>
Run Code Online (Sandbox Code Playgroud)
我可以用空格符号开始字符串:
<TextBlock Text=" {0}"/>
Run Code Online (Sandbox Code Playgroud)
但我正在寻找更好的解决方案.
我在我的视图中有下一个代码:
<Style x:Key="documentFileNameStyle">
<Setter Property="TextBlock.Foreground" Value="Gray"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Untitled}" Value="True">
<Setter Property="TextBlock.FontStyle" Value="Italic"/>
<Setter Property="TextBlock.Text" Value="no file name"/>
</DataTrigger>
</Style.Triggers>
</Style>
<DataTemplate x:Key="documentTemplate">
<TextBlock Text="{Binding Path=FileName}" Style="{StaticResource documentFileNameStyle}"/>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
但是将TextBlock.Text设置为字符串不起作用.TextBlock.FontStyle更改为Italic,因此整个触发器正常工作.怎么了?
我有一个非常复杂的视图,在选项卡控件中有多个选项卡.在一个选项卡上有一个带有装饰层的控件.Adorner层在MouseLeftButtonDown事件处理程序中调用CaptureMouse来捕获鼠标输入.一切正常.
但是,如果我按特定顺序切换视图上的选项卡然后单击adorner图层则无法捕获鼠标输入:CaptureMouse()返回false.同时Mouse.Captured返回null.托管装配层的控件继续正常工作,甚至能够捕获鼠标.
无法提供任何代码,因为有许多自定义控件在运行.在简化的布局中,一切正常.
任何有关CaptureMouse失败的建议?
wpf ×4
c# ×2
xaml ×2
adornerlayer ×1
datatrigger ×1
gridsplitter ×1
mousecapture ×1
roslyn ×1
styles ×1
syntax ×1
textblock ×1