当我有条件时,使用Linq to SQL检索随机行的最佳(和最快)方法是什么,例如某些字段必须为true?
在wcf中,在DataMember属性上应用属性有 什么区别
private int m_SomeValue;
[DataMember]
public int SomeValue {
get {...}
set {...}
}
Run Code Online (Sandbox Code Playgroud)
而不是成员变量
[DataMember]
private int m_SomeValue;
public int SomeValue {
get {...}
set {...}
}
Run Code Online (Sandbox Code Playgroud)
?
我有一个ListBox带ItemTemplate组成的TextBlock和ComboBox.问题是TextBlock每个项目内部文本的宽度不同,ComboBox控件未对齐.
如何TextBlock在模板中设置所有项目的宽度相同,哪个是最宽的?
这是我的xaml:
<ListBox MinHeight="100" ItemsSource="{Binding Trainees}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" Grid.Column="0">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}, {1}">
<Binding Path="LastName" />
<Binding Path="FirstName" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<ComboBox HorizontalAlignment="Left" Grid.Column="1"
ItemsSource="{Binding Source={StaticResource Functions}}" SelectedValue="{Binding Path=Function}"
MinWidth="100" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个透明背景的图像,以显示在网页上.
我尝试了几种技术,但背景总是黑色的.
如何创建透明图像然后在其上绘制一些线条?
我有一个Button ControlTemplate和我试图修改DropShadowEffect上Border使用Trigger.这是我的Xaml:
<Button.Template>
<ControlTemplate TargetType="Button">
<Border x:Name="ButtonBorder" Margin="10" CornerRadius="5" Background="Gray">
<Border.Effect>
<DropShadowEffect ShadowDepth="5" x:Name="BorderEffect" />
</Border.Effect>
<ContentPresenter HorizontalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter Property="Background" TargetName="ButtonBorder" Value="LightGray" />
</Trigger>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Margin" TargetName="ButtonBorder" Value="13,13,7,7" />
<!-- this is where I get the error -->
<Setter Property="ShadowDepth" TargetName="BorderEffect" Value="2" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
Run Code Online (Sandbox Code Playgroud)
我得到错误声明无法找到BorderEffect.
我也尝试过:
<Setter Property="Effect.ShadowDepth" TargetName="ButtonBorder" Value="2" />
Run Code Online (Sandbox Code Playgroud)
但我也得到一个错误,告诉我ShadowDepth在类型的对象上找不到属性Effect(因为它使用的是基类而不是DropShadowEffect)
我怎么解决这个问题?
我正在从wcf Web服务检索数据,当数据超过20万条记录时,我得到一个异常,如下:
System.ServiceModel.CommunicationException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, …Run Code Online (Sandbox Code Playgroud) 我有一个单元测试,测试是否抛出异常,但是这个异常只是抛出调试模式(通过[条件("DEBUG")]属性).如果我在发布模式下运行此测试,则会失败.我试图在测试中应用相同的属性,但没有考虑到它.
如何在发布模式下排除测试?在Release模式下运行单元测试甚至是否应该坚持调试模式是否有意义?
有没有一种更好的方法来设置C#中的mimetypes而不是我想要提前感谢的那种.
static String MimeType(string filePath)
{
String ret = null;
FileInfo file = new FileInfo(filePath);
if (file.Extension.ToUpper() == ".PDF")
{
ret = "application/pdf";
}
else if (file.Extension.ToUpper() == ".JPG" || file.Extension.ToUpper() == ".JPEG")
{
ret = "image/jpeg";
}
else if (file.Extension.ToUpper() == ".PNG")
{
ret = "image/png";
}
else if (file.Extension.ToUpper() == ".GIF")
{
ret = "image/gif";
}
else if (file.Extension.ToUpper() == ".TIFF" || file.Extension.ToUpper() == ".TIF")
{
ret = "image/tiff";
}
else
{
ret = "image/" + file.Extension.Replace(".", ""); …Run Code Online (Sandbox Code Playgroud) 我正在使用此功能关闭现有表单并打开一个新表单.
如果没有exixting表单,则会抛出错误.
错误:
目标:System.Object MarshaledInvoke(System.Windows.Forms.Control,System.Delegate,System.Object [],Boolean)
消息:在创建窗口句柄之前,无法在控件上调用Invoke或BeginInvoke.
Stack:at System.Windows.Forms.Control.MarshaledInvoke(Control caller,Delegate method,Object [] args,Boolean synchronous)
因此,在关闭表单之前需要检查是否打开任何表单以避免错误.怎么样?
static public void NewMainForm(Form main, bool ClosePreviousMain)
{
if (main != null)
{
Global.ActiveForm = main.Text;
if (ClosePreviousMain & MyContext.curMain != null)
{
MyContext.curMain.FormClosed -= new FormClosedEventHandler(main_FormClosed);
//Need to check for any form active and then close the form.
MyContext.curMain.Invoke(new Action(MyContext.curMain.Dispose));
}
MyContext.curMain = main;
MyContext.curMain.FormClosed += new FormClosedEventHandler(main_FormClosed);
MyContext.curMain.ShowDialog();
}
}
Run Code Online (Sandbox Code Playgroud) 如果你有一个绑定到DataView的DataGridView(someDataTable.DefaultView).
..并且从代码对基础DataTable中的行执行许多编辑.
是否可以推迟更新DataGridView,直到您决定完成编辑行为止?
实际上,DataGridView在每次编辑后都会更新,如果您不需要即时反馈,那么如果您一个接一个地更新DataTable中的许多行,那么效率很低,并且会有一些视觉冲突.
c# ×6
.net ×5
asp.net ×2
wcf ×2
winforms ×2
wpf ×2
ado.net ×1
datagridview ×1
debugging ×1
gdi+ ×1
itemtemplate ×1
linq-to-sql ×1
listbox ×1
sockets ×1
triggers ×1
unit-testing ×1
width ×1
windows ×1