小编Val*_*l M的帖子

WPF按钮中的文本内容未垂直居中

有没有理由为什么WPF按钮的文本内容出现在文本上方的不需要的空间?

我在StackPanel中有一个按钮.这个按钮是一个简单的关闭按钮,所以我希望它显示为一个方形按钮,其中有一个"x".我已将我的填充设置为零,并将Horizo​​ntalContentAlign和VerticalContentAlign设置为Center,但"x"仍然出现在按钮的底部(如果我的FontSize相对于我的高度太大,甚至会被截断).就好像按钮顶部有一些填充,可以防止文本使用完整的垂直空间.

我的XAML是:

<StackPanel Orientation="Horizontal">
        <Label Content="{Binding GenderFilter.Title}" FontWeight="Bold" Width="60" />
        <Button Padding="0" Width="15" Height="15" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="12">x</Button>
        <Label Content="{Binding GenderFilterExpander.SelectedValue}" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

如果我将我的按钮VerticalContentAlign属性设置为Stretch甚至Top,问题就完全一样了.如果我删除高度和重量属性,以便按钮确定它自己,那么控件不会显示为正方形而是直立矩形,并且"x"仍然不居中.

更新:虽然按钮和内容现在都完美居中,但按钮仍然显示得比它需要的大得多,就像正在应用高填充一样.

我的资源样式定义现在如下:

<Style x:Key="ClearFilterButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Padding" Value="0" />
    <Setter Property="Width" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=ActualHeight}" />
    <Setter Property="HorizontalContentAlignment" Value="Center" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Content" Value="X" />
    <Setter Property="FontSize" Value="8" />
</Style>
Run Code Online (Sandbox Code Playgroud)

按钮本身定义为:

<Expander.Header>
    <StackPanel Orientation="Horizontal">
            <Label Content="{Binding GenderFilter.Title}" FontWeight="Bold" Width="60" />
            <Button Style="{StaticResource ClearFilterButtonStyle}"
                                    Visibility="{Binding GenderFilterExpander.ClearFilterVisibility}" />
            <Label Content="{Binding GenderFilterExpander.SelectedValue}"
                                   Visibility="{Binding GenderFilterExpander.SelectedValueVisibility}" /> …
Run Code Online (Sandbox Code Playgroud)

wpf xaml wpf-controls

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

匹配行存在于另一个表中时的UPDATE行

我需要更新表上的字段,只有当另一个表中存在匹配的行时才更新,对于主表中当前列为空的所有行.

这是我想要实现的目标的描述:

UPDATE [LenqReloaded].[dbo].[Enquiry] A 
SET [ResponseLetterSent] = 1
WHERE [ResponseLetterSent] IS NULL
   AND EXISTS
       (
           SELECT * FROM [LenqReloaded].[dbo].[Attachment] B 
           WHERE A.[EnquiryID] = B.[EnquiryID]
       )
Run Code Online (Sandbox Code Playgroud)

这在语法上是不正确的.

我无法通过IF EXISTS ...语句对其进行编码,因为我没有[EnquiryID]而没有从表中读取数据.

我该如何格式化UPDATE语句?

sql t-sql

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

我可以在MVC SelectList中自定义数据文本字段,以便与HtmlHelper.DropDownList一起使用,而无需创建新的结构或类吗?

我正在从List(T)类创建一个SelectList,用于在MVC视图中填充HtmlHelper.DropDownList,在Select List构造函数中设置dataValueField和dataTextField.应该显示的文本不会与我的类中的某个属性激动匹配,仍然需要进行操作.有没有办法通过SelectList构造函数执行此操作?我意识到我可以通过创建一个结构或类来用作Select列表的IEnumerable输入,但如果我不需要,我不想这样做.

我的控制器代码目前是:

        var members = MemberService.GetAll();
        this.ViewData["Members"] = new SelectList(members, "Id", "Name");
Run Code Online (Sandbox Code Playgroud)

我的观看代码目前是:

        <%= Html.DropDownList("Members") %>
Run Code Online (Sandbox Code Playgroud)

我希望能够通过组合(和格式化)两个属性来预先格式化字段,而不是"姓氏"作为我的显示字段.

model-view-controller asp.net-mvc

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

使用http:\\ URL的WPF图像UriSource和数据绑定

我在WPF用户控件中显示带有Web URL的图像时遇到问题.我已经解决了2008年8月在本网站上提出的类似问题的所有建议(图像UriSource和数据绑定),但这些建议都没有奏效.

我想做的是:

<Image Width="50" Name="MemberImage">
    <Image.Source>
        <BitmapImage DecodePixelWidth="50" UriSource="{Binding Member.ImageFilePathUri}" />
    </Image.Source>
</Image>
Run Code Online (Sandbox Code Playgroud)

ImageFilePathUri是一个从字符串路径创建的Uri:

public Uri ImageFilePathUri
    {
        get
        {
            return new Uri(this.ImageFilePath);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这样就必须设置"Property'UriSource'或属性'StreamSource'." 错误如预期.

我也尝试过使用值转换器:

public class ImageConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        var image = new BitmapImage();
        image.BeginInit();
        if (value != null)
        {
            image.UriSource = new Uri((string)value);
        }
        image.DecodePixelWidth = 50;
        image.EndInit();
        return image;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,使用以下方法绑定它:

<Image Name="TestImage" Width="50" Source="{Binding Path=Member.ImageFilePath, Converter=Parliament.HansardApplicationSuite.Logging.Helpers.ImageConverter}"></Image> …
Run Code Online (Sandbox Code Playgroud)

c# data-binding url wpf xaml

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

如何将WPF BitmapImage UriSource属性设置为相对路径?

我正在使用BitmapImage类在WPF中加载图像.当我为UriSource提供绝对路径时,我的代码工作得很好,但当我尝试使用相对路径时却没有.

我的XAML是:

<Image Width="50" Name="MemberImage" HorizontalAlignment="Left">
    <Image.Source>
        <BitmapImage DecodePixelWidth="50" UriSource="questionmark.jpg" />
    </Image.Source>
</Image>
Run Code Online (Sandbox Code Playgroud)

questionmark.jpg被添加到项目中,其中"资源构建操作"和"复制到输出目录"设置为"始终复制".我得到的错误是"文件[文件名]不是项目的一部分,或者它的'Build Action'属性未设置为'Resource'".当我使用UriSource的绝对路径但是显然不会这样做时,这种方法有效.

我该如何在XAML中定义我的UriSource?

wpf uri bitmapimage

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

如何在ListView控件中为默认情况下检查的第一个WPF RadioButton设置XAML?

我有一个WPF ListView控件包含许多使用数据绑定的RadioButton控件.我希望默认情况下检查组中的第一个RadioButton,最好是在XAML中而不是以编程方式设置,但是没有设法实现这一点.

我控制的XAML是:

        <ListView ItemsSource="{Binding OptionsSortedByKey}" >
            <ListView.ItemTemplate>
                <DataTemplate DataType="{x:Type Logging:FilterOptionsRadioListViewModel}">
                    <RadioButton Content="{Binding Value}" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
Run Code Online (Sandbox Code Playgroud)

OptionsSortedByKey属性是SortedList.

我通过在Loaded事件中设置RadioButton控件的IsChecked属性来做到这一点:

        var button = sender as RadioButton;

        if (button != null)
        {
            if (button.Content.ToString().ToUpperInvariant() == "ALL")
            {
                button.IsChecked = true;
            }
        }
Run Code Online (Sandbox Code Playgroud)

我更喜欢通过XAML中的数据绑定来做到这一点.有一个简单的方法吗?

wpf binding listview wpf-controls radio-button

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

如何在动态linq中格式化日期文字?

我使用动态Linq返回用户输入搜索条件的数据.除了用户选择的日期之外,我的查询工作正常.我目前的代码是:

        StringBuilder whereClause = new StringBuilder();

        if (startDate.HasValue || endDate.HasValue)
        {
            DateTime searchStartDate = startDate.HasValue ? startDate.Value : DateTime.MinValue;
            DateTime searchEndDate = endDate.HasValue ? endDate.Value : DateTime.MaxValue;

            whereClause.AppendFormat("Date >= {0} && Date <= {1}",
                searchStartDate.Date.ToUniversalTime(),
                searchEndDate.Date.ToUniversalTime());
        }

        if (whereClause.Length > 0)
        {
            return (from p in this.repository.GetQueryable<Party>() select p)
                .Where(whereClause.ToString())
                .ToList();
        }
Run Code Online (Sandbox Code Playgroud)

查询失败,因为在DateTime字段和Int32字段之间进行比较,这意味着查询已将我的日期文字解释为整数.

我该如何格式化日期?

c# linq datetime dynamic

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

为什么我不能在WCF类中使用KnownType属性?

我正在使用WCF来检索对象的集合.这些对象都是ProcedureText类型,但可以是子类SuspensionText或ResumptionText,它们都继承自ProcedureText.

public class ProcedureText { }
public class SuspensionText : ProcedureText { }
public class ResumptionText : ProcedureText { }
Run Code Online (Sandbox Code Playgroud)

我的OperationContract指定一个返回ProcedureText对象数组的方法:

[OperationContract]
[WebGet(UriTemplate = "procedureTexts")]
ProcedureText[] GetProcedureTexts();
Run Code Online (Sandbox Code Playgroud)

如果我将所有对象强制转换为ProcedureText但我想保留使用子类型的区别,这是有效的.我原本希望使用KnownType属性来执行此操作,并希望能够通过将其添加到我的ProcedureText类来实现:

[System.Runtime.Serialization.KnownType(typeof(SuspensionTextDto))]
[System.Runtime.Serialization.KnownType(typeof(ResumptionTextDto))]
public class ProcedureText { }
Run Code Online (Sandbox Code Playgroud)

这不起作用,因为编译器无法解析System.Runtime.Serialization.KnownType.我从文档中知道该属性是.NET Framework 4的一部分,但我使用的是.NET Framework 4,这是我项目的Target Frameweork.

为什么我需要设置为能够使用该属性?

wcf serialization

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