小编Sha*_*boo的帖子

wpf:如何使ComboBoxItems在xaml中保存整数

好吧,我必须在这里冻结大脑......

我有一个包含6个项目的ComboBox,我正在尝试将所选项目绑定到整数值.它不起作用,我怀疑它是因为ComboBoxItem是字符串.我不想在代码后面填写一个列表来填充这个小盒子,所以在xaml中是否有一种方法可以告诉组合框架它们是否保持整数?喜欢的东西<x:Int>2</x:Int>可能?

XAML:

<ComboBox SelectedItem="{Binding SavedPrintTicket.PagesPerSheet}">
    <ComboBoxItem>1</ComboBoxItem>
    <ComboBoxItem>2</ComboBoxItem>
    <ComboBoxItem>4</ComboBoxItem>
    <ComboBoxItem>6</ComboBoxItem>
    <ComboBoxItem>8</ComboBoxItem>
    <ComboBoxItem>16</ComboBoxItem>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

wpf binding combobox selecteditem

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

WPF,Prism v2,模态对话框中的区域,在代码后面添加区域

我有一个复合WPF应用程序.在我的一个模块中,我想制作一个向导并将步骤显示在一个区域中,这样我就可以更轻松地在两个步骤之间切换.最初我让这个向导显示在选项卡区域,嵌套区域工作正常.现在我想把它变成一个模态对话框,但是在打开之后,内部区域永远不会被区域管理器注册; 所以我无法添加我的向导步骤.

我的印象是区域管理器是全局的,只需添加cal:RegionManager.RegionName ="WizardSteps"就可以了,但显然不是.

如果我将区域管理器传递给视图,我可以使用它...有谁知道如何在代码后面的ContentControl中添加区域?

wpf prism composite

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

WPF自定义控件:DependencyProperty从不设置(仅在许多属性中的1个)

我创建了一个名为AddressForm的自定义控件,它继承自Control.该控件用于显示IAddress对象的字段.

最初我在Silverlight中制作了这个控件,现在我试图让它在WPF .net 4.5中运行

该控件定义了9个不同的依赖属性,除了一个外,所有属性都正常工作.当然,不工作的是Address对象本身!

Control的Address属性永远不会收到值.我在地址的Getter中放了一个断点,该属性被调用,地址对象不为null,但控件没有收到它.

输出屏幕中没有异常,也没有错误消息.

控制 :

public class AddressForm : Control, INotifyPropertyChanged
{
    [...]

    public static readonly DependencyProperty AddressProperty = DependencyProperty.Register("Address", typeof(IAddress), typeof(AddressForm), new PropertyMetadata( AddressChanged));
    public IAddress Address 
    {
        get { return (IAddress)GetValue(AddressProperty); }
        set { SetValue(AddressProperty, value); } 
    }

    private static void AddressChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        //break-point here never gets hit
        AddressForm form = d as AddressForm;
        if (form != null)
            form.OnAddressSet();
    }

    private void OnAddressSet()
    {
        //break-point here never gets …
Run Code Online (Sandbox Code Playgroud)

dependency-properties custom-controls wpf-4.5

8
推荐指数
1
解决办法
353
查看次数

WPF实体无法创建视图的ObjectSet?

我已经为我的实体模型添加了一个数据库视图.现在我想把一个ObjectSet放入我的ObjectContext所以我可以访问我的应用程序中的视图.

对于常规表,我ObjectSet看起来像这样:

private ObjectSet<StarVendor> _StarVendor;
public ObjectSet<StarVendor> StarVendor
{
    get
    {
        if ((_StarVendor == null))
        {
            _StarVendor = base.CreateObjectSet<StarVendor>("Stratus_X_TestEntities.StarVendors");
        }
         return _StarVendor;
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我对我的观点做了同样的事情:

private ObjectSet<CatalogItemSearch> _CatalogItemSearch;
public ObjectSet<CatalogItemSearch> CatalogItemSearch
{
    get
    {
        if ((_CatalogItemSearch == null))
        {
            _CatalogItemSearch = base.CreateObjectSet<CatalogItemSearch>("Stratus_X_TestEntities.CatalogItemSearch");
        }
        return _CatalogItemSearch;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当代码运行时,我得到一个例外:

System.InvalidOperationException"无法找到EntitySet名称'Stratus_X_TestEntities.CatalogItemSearch'"

我知道对于View我不需要提供的添加/更新/删除功能ObjectSet.

是否有我应该使用的替代Set类型?

或者这个错误可能来自与其观点完全无关的事情?

谢谢

c# wpf entity-framework

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

silverlight MatchTimeoutInMilliseconds bug:解析DomainServiceClientCodeGenerator

Silverlight 5 .Net Framework 4

我正在尝试为RIA代码生成器中最近的错误实现一种解决方法 "无法找到MatchTimeoutInMilliseconds" https://connect.microsoft.com/VisualStudio/feedback/details/1988437/generated-code-for-silverlight-references -matchtimeoutinmilliseconds -这-不-不存在

我正在尝试使用Lazebnyy的解决方法,但我似乎无法解决DomainServiceClientCodeGenerator.

Lazebnyy写道:

从WebProejct中的Nuget或将包含代码生成类的类库安装RIAServices.T4.PM>安装包RIAServices.T4

创建两个类

[DomainServiceClientCodeGenerator(typeof(MyServicesEntityGenerator),"C#")]
public class MyServicesClientCodeGenerator : CSharpClientCodeGenerator
{
    protected override EntityGenerator EntityGenerator
    {
        get
        {
            return new MyServicesEntityGenerator();
        }
    }
}

public class MyServicesEntityGenerator : CSharpEntityGenerator
{
    protected override void GenerateAttributes(IEnumerable<Attribute>attributes, bool forcePropagation)
    {
        List<Attribute> newAttributes = new List<Attribute>(attributes);
        List<Attribute> regularExpressionAttributes = (from c in attributes where c.GetType() == typeof(RegularExpressionAttribute) select c).ToList();

        newAttributes.RemoveAll(delegate(Attribute attr)
                {
                    return attr.GetType() == typeof(RegularExpressionAttribute);
                });

        base.GenerateAttributes(newAttributes, forcePropagation);

        foreach …
Run Code Online (Sandbox Code Playgroud)

.net c# silverlight ria

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

Maui ImageButton 与 FontImageSource - 如何调整图像大小?.net 8

我刚刚将我的 maui android/ios 项目更新为 .net 8,我的 ImageButtons 现在呈现不同的方式。

在 .net 7 中,我没有设置 ImageButton 的高度/宽度,按钮的大小将根据填充进行调整。我找到了一个我喜欢的平衡,它的图像显示有一些填充,这样它就不会被圆角半径切断。

在 .net 8 中,我需要设置高度/宽度才能显示 ImageButton。但是,设置 ImageButton 高度/宽度尺寸后,填充值没有任何区别(这与 .net 7 中的行为相同)。

由于某种原因,FontImageSource 现在渲染得比以前更大,并且填充没有任何区别,我无法让图像很好地适合按钮而不被角半径切断。FontImageSource 图标没有改变。

在此输入图像描述

我尝试了各种不同的高度/宽度、填充和角半径,以及设置 fontImageSource 的大小,但我无法复制 .net 7 中此按钮的外观!

我想让它看起来像上图中顶部中间的图标。有谁知道需要更改什么才能使图标正确显示?

<Grid Margin="0" BackgroundColor="Black" >
    <Grid.RowDefinitions>
        <RowDefinition Height="40" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <ImageButton Grid.Row="1" Margin="15,0,15,10" 
        HorizontalOptions="End" 
        VerticalOptions="End" 
        HeightRequest="40" 
        WidthRequest="40"
        Padding="5"
        CornerRadius="20"
        BackgroundColor="#32578f">
        <ImageButton.Source>
            <FontImageSource  
                Glyph="{x:Static m:MaterialOutlined.Grid_view}" 
                FontFamily="MaterialOutlined" 
                Color="White" 
                Size="10"/>
        </ImageButton.Source>
    </ImageButton>
</Gird>
Run Code Online (Sandbox Code Playgroud)

imagebutton maui maui-android .net-8.0

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

Visual Studio 2012 - silverlight - XAML设计器 - 在前/后插入网格行

刚刚切换到visual studio 2012,我无法弄清楚如何通过xaml设计器将新行插入到silverlight网格中.

在visual studio 2010中,我们可以通过左键单击> rows> insert before轻松地将行和列插入到我们的silverlight网格中.当我们这样做时,它会自动重新编号所有其余控件的行号.

我不想手动重新编号每个控件,这个超级方便的功能是否已从2012年删除?或者是否有一些新的方法来实现这一目标?

xaml-designer silverlight-5.0 visual-studio-2012

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

wpf使用VisualStateManager来更改Visibility

我正在努力将一些代码从silverlight转换为WPF,而我的VisualStates无法正常工作.

我使用visualstatemanager来控制某些文本字段的可见性.我没有使用任何过渡来为变化设置动画,我只想让字段在一个状态下折叠,然后在另一个状态下显示.

来自silverlight的Xaml:

<VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="LostPasswordStates">
            <VisualState x:Name="LostPassword_Start">
                <Storyboard>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="lbl_UserName" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Visible" />
                    </ObjectAnimationUsingKeyFrames>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="txt_UserName" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Visible" />
                    </ObjectAnimationUsingKeyFrames>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="txt_UserName" Storyboard.TargetProperty="(TextBox.IsReadOnly)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="False" />
                    </ObjectAnimationUsingKeyFrames>

                </Storyboard>
            </VisualState>
            <VisualState x:Name="LostPassword_Success">
                <Storyboard>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="lbl_UserName" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Collapsed" />
                    </ObjectAnimationUsingKeyFrames>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="txt_UserName" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Collapsed" />
                    </ObjectAnimationUsingKeyFrames>

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="btn_Reset" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Collapsed" />
                    </ObjectAnimationUsingKeyFrames>

                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
Run Code Online (Sandbox Code Playgroud)

我得到以下异常:

PresentationCore.dll中出现未处理的"System.Windows.Media.Animation.AnimationException"类型异常

附加信息:无法使用'System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames'为'System.Windows.Controls.TextBox'上的'Visibility'属性设置动画.有关详细信息,请参阅内部异常

所以我的问题是:

如果我不能使用System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames为此,我应该使用什么?

wpf visualstatemanager

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