我正在定义一个XAML DrawingBrush资源,我想绘制一个自定义形状.我找到了以下GeometryDrawing示例:
<GeometryDrawing Geometry="M0,0.1 L0.1,0 1,0.9, 0.9,1z" Brush="Gray" />
Run Code Online (Sandbox Code Playgroud)
做什么的M,L以及z在信件Geometry的属性是什么意思?他们叫什么?
OpenFileDialog的ShowDialog方法返回一个可以为空的布尔值,如果用户单击OK则设置为true,如果单击Cancel,则设置为false.什么时候回来null?文档没有说.
我有一个ToggleButton与它的IsChecked属性绑定到使用单向绑定属性.
<ToggleButton
Command="{Binding Path=SomeCommand}"
IsChecked="{Binding Path=SomeProperty, Mode=OneWay}" />
Run Code Online (Sandbox Code Playgroud)
该SomeCommand切换布尔SomeProperty值,一个PropertyChanged事件引发的SomeProperty.
如果我更改SomeProperty了我的viewmodel,ToggleButton则会正确压下.但是,如果我单击该ToggleButton绑定似乎丢失,并且不再根据值来检查该按钮SomeProperty.关于如何解决这个问题的任何想法?
微软已经将WPF的Classic,Luna,Royale和Aero主题作为XAML资源词典下载.
我在哪里可以下载它们?我永远找不到链接!
我有一个C#泛型:
public class Generic<TParameter> { ... }
Run Code Online (Sandbox Code Playgroud)
似乎我不能使用未绑定的类型作为类型参数.我error CS1031: Type expected尝试以下时得到:
var lGenericInstance = new Generic<List<>>();
Run Code Online (Sandbox Code Playgroud)
如何将未绑定类型用作泛型类型参数?有变通方法吗?我的泛型类只是使用反射,所以我可以获得所提供类型的成员列表作为字符串.
更新:我的答案是关于未绑定类型的问题,所以我已经跟进了一个单独的问题来解决我的具体问题.
我正在使用googlemockstd::fstream在我的单元测试中模拟出一个对象,如下所示:
TEST_F(SomeTest, SomethingIsDoneCorrectly)
{
class MockFstream : public std::fstream {};
MockFstream lMockFstream;
// Expectations and assertions here
}
Run Code Online (Sandbox Code Playgroud)
当我编译时,我得到以下警告:
警告1警告C4250:'SomeTest_SomethingIsDoneCorrectly_Test :: TestBody :: MockFstream':通过优势继承'std :: basic_istream <_Elem,_Traits> :: std :: basic_istream <_Elem,_Traits> :: _ Add_vtordisp1'
警告2警告C4250:'SomeTest_SomethingIsDoneCorrectly_Test :: TestBody :: MockFstream':通过优势继承'std :: basic_ostream <_Elem,_Traits> :: std :: basic_ostream <_Elem,_Traits> :: _ Add_vtordisp2'
我更喜欢干净的构建输出,所以我想要抑制这些特定的警告,但我正在编写跨平台代码,所以我也更愿意避免使用特定于编译器的#pragmas.
我可以在googlemock对象中做些什么来隐藏这些警告吗?
我有一个TextBlock在Grid其Padding属性设置为5,有时候最后一个字符被切断,这取决于字符串Text属性设置为.
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SomeClass">
<ScrollViewer Padding="5" VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label
Grid.Row="0" Grid.Column="0"
Content="SomeLabel"
HorizontalAlignment="Right"
HorizontalContentAlignment="Right"
VerticalAlignment="Center" />
<TextBlock
Grid.Row="0" Grid.Column="1"
HorizontalAlignment="Left"
Padding="5"
Text="0x0F"
TextWrapping="Wrap"
VerticalAlignment="Top" />
</Grid>
</ScrollViewer>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
当Text设置为0x0F与F不可见.当它设置为0xAB字符串显示就好了.设置Padding为0也使字符串显示正常.
我如何UserControl从其内部绑定一个属性ResourceDictionary?我想要一个我在我的资源中声明的对象DataContext与UserControl它包含在的对象相同:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Some.Namespace"
DataContext="{Binding Path=ViewModel, RelativeSource={RelativeSource Self}}">
<UserControl.Resources>
<local:SomeClass
x:Key="SomeClass"
DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
</UserControl.Resources>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
在运行时我收到错误:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='UserControl', AncestorLevel='1''. BindingExpression:Path=DataContext; DataItem=null; target element is 'SomeClass' (Name=''); target property is 'DataContext' (type 'Object')
我是一个单元测试类的属性,其值经常变化,这取决于它从另一个组件接收的通信.如果该类在5秒内未收到任何通信,则该属性将恢复为默认值.
我很容易存根和模拟通信组件,以便触发我想要测试的值.问题是如果我在繁忙的机器上运行我的单元测试(比如构建机器),并且有足够的延迟导致属性默认,那么我的单元测试将失败.
在模拟各种通信条件时,您将如何测试以确保此属性具有适当的值?
一个想法是重构我的代码,以便我可以存根控制超时的类的部分.另一种方法是编写我的单元测试,以便它可以检测是否由于超时而失败并在测试结果中指出.
wpf ×7
xaml ×2
binding ×1
c# ×1
c++ ×1
data-binding ×1
drawing ×1
fstream ×1
generics ×1
mocking ×1
padding ×1
shape ×1
textblock ×1
themes ×1
timeout ×1
togglebutton ×1
treeview ×1
unit-testing ×1
visual-c++ ×1
winapi ×1