小编Jul*_*lin的帖子

从Linq到Sql的随机行

当我有条件时,使用Linq to SQL检索随机行的最佳(和最快)方法是什么,例如某些字段必须为true?

.net c# linq-to-sql

110
推荐指数
5
解决办法
6万
查看次数

WCF:属性与成员的DataMember属性

在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)

.net wcf serialization

53
推荐指数
3
解决办法
4万
查看次数

如何在WPF的列表框中为所有项目创建相同宽度的列?

我有一个ListBoxItemTemplate组成的TextBlockComboBox.问题是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)

wpf listbox itemtemplate width

42
推荐指数
1
解决办法
2万
查看次数

使用GDI +创建具有透明背景的图像?

我正在尝试创建一个透明背景的图像,以显示在网页上.
我尝试了几种技术,但背景总是黑色的.
如何创建透明图像然后在其上绘制一些线条?

c# asp.net gdi+

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

如何通过ControlTemplate中的Trigger设置DropShadowEffect的属性?

我有一个Button ControlTemplate和我试图修改DropShadowEffectBorder使用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)

我怎么解决这个问题?

wpf triggers controltemplate

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

System.ServiceModel.CommunicationException:基础连接已关闭

我正在从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)

.net c# sockets asp.net wcf

15
推荐指数
1
解决办法
5万
查看次数

如何才能在DEBUG模式下运行单元测试?

我有一个单元测试,测试是否抛出异常,但是这个异常只是抛出调试模式(通过[条件("DEBUG")]属性).如果我在发布模式下运行此测试,则会失败.我试图在测试中应用相同的属性,但没有考虑到它.

如何在发布模式下排除测试?在Release模式下运行单元测试甚至是否应该坚持调试模式是否有意义?

.net debugging unit-testing

12
推荐指数
4
解决办法
6471
查看次数

在C#中设置MimeType

有没有一种更好的方法来设置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)

c#

11
推荐指数
3
解决办法
2万
查看次数

在c#windows应用程序中找到打开的表单

我正在使用此功能关闭现有表单并打开一个新表单.

如果没有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)

c# windows winforms

9
推荐指数
3
解决办法
4万
查看次数

编辑基础DataTable时推迟DataGridView更新

如果你有一个绑定到DataView的DataGridView(someDataTable.DefaultView).

..并且从代码对基础DataTable中的行执行许多编辑.

是否可以推迟更新DataGridView,直到您决定完成编辑行为止?

实际上,DataGridView在每次编辑后都会更新,如果您不需要即时反馈,那么如果您一个接一个地更新DataTable中的许多行,那么效率很低,并且会有一些视觉冲突.

.net c# ado.net datagridview winforms

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