GVKun编程网logo

WPF colorAnimation 边框画笔颜色抛出“System.Windows.Markup.XamlParseException”(wpf textbox 边框颜色)

3

对于WPFcolorAnimation边框画笔颜色抛出“System.Windows.Markup.XamlParseException”感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍wpft

对于WPF colorAnimation 边框画笔颜色抛出“System.Windows.Markup.XamlParseException”感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍wpf textbox 边框颜色,并为您提供关于.net – System.Drawing(GDI)vs System.Windows.Media(WPF)vs Direct2D DirectWrite WIC、ASP.NET Core 3.1:System.InvalidCastException:无法将“System.Int32”类型的对象转换为“System.Int64”类型、Automapper 错误:System.InvalidOperationException:'缺少从 System.String 到 System.Char 的映射、C# WPF 中的错误:“System.Windows.Style”不是属性“System.Windows.Controls.Control.Template” MainViewResource.xaml主窗口.xaml的有用信息。

本文目录一览:

WPF colorAnimation 边框画笔颜色抛出“System.Windows.Markup.XamlParseException”(wpf textbox 边框颜色)

WPF colorAnimation 边框画笔颜色抛出“System.Windows.Markup.XamlParseException”(wpf textbox 边框颜色)

如何解决WPF colorAnimation 边框画笔颜色抛出“System.Windows.Markup.XamlParseException”

我正在尝试使用 Style.Triggers 在边框画笔上实现彩色动画。

viewmodel 改变了每个 Border 颜色有界的集合。

我猜 UI 元素没有初始化但是条件满足然后抛出异常:

“附加信息:无法解析属性路径 ''BorderBrush.Color'' 中的所有属性引用。请验证适用的对象是否支持这些属性。”

这里是 View.cs.xaml 代码:

<HierarchicalDataTemplate DataType="{x:Type model:SchemaNode}" 
                                          ItemsSource="{Binding Children}">
    <Border CornerRadius="40">
        <Border.Style>
            <Style targettype="Border">
                <Setter Property="Background" Value="{DynamicResource MaterialDesignPaper}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Closed}" Value="True">
                        <Setter Property="Background" Value="{Binding Outline}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Border.Style>
        <Border.InputBindings>
            <MouseBinding MouseAction="LeftDoubleClick"
                  Command="{Binding ondoubleclick}" CommandParameter="{Binding GlobalId}"/>
        </Border.InputBindings>
        <Border.ContextMenu>
            <ContextMenu ItemsSource="{Binding ContextActions}" Width="150" Placement="Mouse">
                <ContextMenu.ItemTemplate>
                    <DataTemplate DataType="{x:Type helper:ContextAction}">
                        <MenuItem Header="{Binding Header}" Command="{Binding Command}"/>
                    </DataTemplate>
                </ContextMenu.ItemTemplate>
            </ContextMenu>
        </Border.ContextMenu>
        <Border BorderThickness="3" CornerRadius="360"
                BorderBrush="{Binding Outline}" Width="{Binding Width}" Height="{Binding Height}">
            <Border.Style>
                <Style targettype="Border">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Located}" Value="True">
                            <DataTrigger.Enteractions>
                                <BeginStoryboard x:Name="LocatedBeginStoryBoard">
                                    <Storyboard Duration="0:0:0.5" RepeatBehavior="Forever" AutoReverse="True">
                                        <ThicknessAnimation Storyboard.TargetProperty="BorderThickness" Duration="0:0:0.4"
                                                            FillBehavior="HoldEnd"
                                                            To="5"/>
                                        <ThicknessAnimation Storyboard.TargetProperty="BorderThickness"
                                                            FillBehavior="HoldEnd"
                                                            BeginTime="0:0:0.4"
                                                            To="5"/>
                                        <ColorAnimation Storyboard.TargetProperty="BorderBrush.Color"
                                                        To="White"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.Enteractions>
                            <DataTrigger.Exitactions>
                                <RemoveStoryboard BeginStoryboardName="LocatedBeginStoryBoard"/>
                            </DataTrigger.Exitactions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
            <Image Height="50"
                   Width="50" Source="{Binding ImageSource,Converter={StaticResource imagePathToImageConverter}}"
                   HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Image.InputBindings>
                    <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding ondoubleclick}" CommandParameter="{Binding GlobalId}"/>
                </Image.InputBindings>
            </Image>
        </Border>
    </Border>
</HierarchicalDataTemplate>

希望我提供了足够的代码来解决这个问题。

解决方法

您通过 BorderBursh 绑定的 Outline 很可能不是 SolidColorBrush 而是 GradientBrush 或只是未分配,因此没有 Color 属性.

您可以通过分配 SolidColorBrush(directyl 或 via 样式)来测试这一点。

<Style TargetType="Border">
    <Style.Setters>
        <Setter Property="BorderBrush" Value="Blue"/>
    </Style.Setters>
    <!-- etc -->

Proof of concept

.net – System.Drawing(GDI)vs System.Windows.Media(WPF)vs Direct2D DirectWrite WIC

.net – System.Drawing(GDI)vs System.Windows.Media(WPF)vs Direct2D DirectWrite WIC

对于处理图像并将用C#编写的Desktop Vista应用程序,您会推荐以下哪种技术(或者您推荐的组合:System.Drawing(GDI)vs System. Windows.Media vs Direct2D DirectWrite WIC.图像处理将涉及各种原始绘图,填充,使用文本,旋转,平移,缩放,直接使用指针处理像素数据.一般来说,上述技术在操作位图方面有多好?

此外,如果有人知道一个好的和详细的比较图表,列出了并排的不同功能和等价物,以及不支持的,这将是伟大的!例如,WPF和Direct2D中是否存在ColorMatrix等价物?例如,在研究了SharpDX对Direct2D的实现后,我留下的印象是即使微软将其定位为GDI的完全替代品,我也无法在Direct2D中找到所有GDI的功能.

另外,考虑到它是2014年,你会说至少对于图像处理(如果不是UI的一部分,WPF似乎是更好的选择),GDI在接下来的5年左右会好吗?或者我应该真的考虑使用所有3种技术,哪种方法效果最好?

谢谢.

解决方法

我目前在一个视觉密集型的C#/ WPF项目中工作,并且在 Python中使用图像处理做了一些最好的黑客攻击.

根据您的预期用途,我将使用以下方法:

>尽可能使用WPF名称空间,即System.Windows.Media.据我所知,System.Drawing和GDI通常使用非托管资源,这可能会产生不希望的,可避免的问题;
>尽可能严格地使用MVVM架构.也就是说,您有一个仅用于显示信息的View层,以及包含业务逻辑的Model和viewmodel层.虽然有些人可能会说视觉内容不属于viewmodel层,但如果你的应用程序处理图像操作,那么你的业务逻辑就像定义一样与View相关(我花了很长时间才弄明白这一点).
>如有疑问,请使用多维数组(在Model / viewmodel中)执行图像处理,并将这些数组绑定到View(使用ValueConverter通过DataBinding).

这样,例如,您可以使用ImageLayerviewmodel类来表示Layer,其中Data属性(或Value或PixelArray或Raster,无论如何)是double [height,width,depth].

我可以详细说明一下,但我不确定是否正确回答你的问题,所以如果你愿意,可以写任何评论.

ASP.NET Core 3.1:System.InvalidCastException:无法将“System.Int32”类型的对象转换为“System.Int64”类型

ASP.NET Core 3.1:System.InvalidCastException:无法将“System.Int32”类型的对象转换为“System.Int64”类型

如何解决ASP.NET Core 3.1:System.InvalidCastException:无法将“System.Int32”类型的对象转换为“System.Int64”类型

Picture Error

我的控制器:

  1. [HttpDelete("{roomId}")]
  2. public async Task<IActionResult> Delete(string roomId)
  3. {
  4. var affectedResult = await _manageRoomService.Delete(roomId);
  5. if (affectedResult == 0)
  6. return BadRequest();
  7. return Ok();
  8. }

我的服务:我尝试调试,但它在代码块 foreach (var image in images) 中停止。

  1. public async Task<int> Delete(string roomId)
  2. {
  3. var room = await _context.Rooms.FindAsync(roomId);
  4. if (room == null)
  5. throw new EWebHotelException($"Cannot find a room: {roomId}");
  6. var images = _context.RoomImages.Where(i => i.RoomId == roomId);
  7. foreach (var image in images)
  8. {
  9. await _storageService.DeleteFileAsync(image.ImagePath);
  10. }
  11. _context.Rooms.Remove(room);
  12. return await _context.SaveChangesAsync();
  13. }

我在 FileStorageService.cs 中的方法:

  1. public async Task DeleteFileAsync(string fileName)
  2. {
  3. var filePath = Path.Combine(_userContentFolder,fileName);
  4. if (File.Exists(filePath))
  5. {
  6. await Task.Run(() => File.Delete(filePath));
  7. }
  8. }

在 RoomImages 表中,列 Id 的类型为 int 32。

Automapper 错误:System.InvalidOperationException:'缺少从 System.String 到 System.Char 的映射

Automapper 错误:System.InvalidOperationException:'缺少从 System.String 到 System.Char 的映射

如何解决Automapper 错误:System.InvalidOperationException:''缺少从 System.String 到 System.Char 的映射

我需要使用 automapper 从 Company 模型中填充 CompanyVM 中的地址字段。一个公司可能有许多地址。最好我想要一个也是主要的活动地址。否则,我只想要一个活动地址。如果不行,给我一个地址。

这是公司模型:

  1. public class Company
  2. {
  3. public int CompanyID { get; set; }
  4. public string Name { get; set; }
  5. public string Type { get; set; }
  6. public string Industry { get; set; }
  7. public string DBA { get; set; }
  8. public string TaxID { get; set; }
  9. public bool Active { get; set; } = true;
  10. public virtual ICollection<Address> Addresses { get; set; } = new List<Address>();

这是地址模型:

  1. public class Address
  2. {
  3. public int AddressID { get; set; }
  4. public string Type { get; set; }
  5. public string Street1 { get; set; }
  6. public string Street2 { get; set; }
  7. public string City { get; set; }
  8. public string State { get; set; }
  9. public string ZipCode { get; set; }
  10. public string County { get; set; }
  11. public string Country { get; set; }
  12. public bool Primary { get; set; } = false;
  13. public bool Active { get; set; } = true;
  14. public int? CompanyCompanyID { get; set; }

我需要绘制其中的许多地图,但现在只是想让它为 Street1 工作。

以下是我尝试使用的自动映射器语句:

  1. public class CompanyProfile : Profile
  2. {
  3. public CompanyProfile()
  4. {
  5. CreateMap<Company,CompanyVM>()
  6. .ForMember(vm => vm.Street,opt => opt.MapFrom(model =>
  7. model.Addresses.Where(x => x.CompanyCompanyID != null && x.Active && x.Primary).Select(x => x.Street1) ??
  8. model.Addresses.Where(x => x.CompanyCompanyID != null && x.Active).Select(x => x.Street1) ??
  9. model.Addresses.Where(x => x.CompanyCompanyID != null).Select(x => x.Street1)))
  10. .ReverseMap();
  11. }
  12. }

这是 CompanyVM:

  1. [Grid2(nameof(CompanyID),FavoritesEnabled = true,RecentRecordAction = "Details",FetchDataOnLoad = true
  2. )]
  3. public class CompanyVM : GridRecordVM
  4. {
  5. public virtual int CompanyID { get; set; }
  6. [GridColumn2(TemplateType = GridTemplateType.DefaultDetailLink,IncludeInGeneralSearch = true)]
  7. public virtual string Name { get; set; }
  8. [GridColumn2]
  9. public virtual string Type { get; set; }
  10. [LockedFilter(FilterOperator.IsEqualTo,true)]
  11. public virtual bool Active { get; set; }
  12. [display(Name = "Industry")]
  13. [MaxLength(20,ErrorMessage = "Industry cannot be longer that 20 characters.")]
  14. public string Industry { get; set; }
  15. [display(Name = "DBA")]
  16. [MaxLength(50,ErrorMessage = "DBA name cannot be longer that 50 characters.")]
  17. public string DBA { get; set; }
  18. [display(Name = "Tax Id")]
  19. [MaxLength(50,ErrorMessage = "TaxID name cannot be longer that 50 characters.")]
  20. public string TaxID { get; set; }
  21. [display(Name = "Street",Description = "Street")]
  22. public string Street { get; set; }
  23. //these items set to ignoremap until mapping sorted out
  24. [display(Name = "City",Description = "City")]
  25. [IgnoreMap]
  26. public string City { get; set; }
  27. [display(Name = "State",Description = "State")]
  28. [IgnoreMap]
  29. public string State { get; set; }
  30. [display(Name = "ZipCode",Description = "ZipCode")]
  31. [IgnoreMap]
  32. public string ZipCode { get; set; }
  33. [Phone]
  34. [display(Name = "Phone Number",Description = "Phone Number")]
  35. [IgnoreMap]
  36. public string PhoneNumber { get; set; }
  37. [EmailAddress]
  38. [display(Name = "Email Address",Description = "Email Address")]
  39. [IgnoreMap]
  40. public string EmailAddress { get; set; }
  41. }

抛出运行时错误:system.invalidOperationException: ''Missing map from System.String to System.Char。使用 CreateMap 创建。''我已经看过很多关于这个问题的帖子,也已经阅读了其中的很多,但对我来说仍然没有意义。我的源和目标字段都是字符串。我做错了什么?

解决方法

解决方案是将 CreateMap .ForMember 语句格式化如下:

  1. CreateMap<Company,CompanyVM>()
  2. .ForMember(x => x.Street,opt => opt.MapFrom(src =>
  3. src.Addresses.Where(x => x.Active && x.Primary).FirstOrDefault() != null
  4. ? src.Addresses.Where(x => x.Active && x.Primary).FirstOrDefault().Street1
  5. : src.Addresses.Where(x => x.Active).FirstOrDefault() != null
  6. ? src.Addresses.Where(x => x.Active).FirstOrDefault().Street1
  7. : src.Addresses.FirstOrDefault() != null
  8. ? src.Addresses.FirstOrDefault().Street1
  9. : string.Empty))

C# WPF 中的错误:“System.Windows.Style”不是属性“System.Windows.Controls.Control.Template” MainViewResource.xaml主窗口.xaml

C# WPF 中的错误:“System.Windows.Style”不是属性“System.Windows.Controls.Control.Template” MainViewResource.xaml主窗口.xaml

如何解决C# WPF 中的错误:“System.Windows.Style”不是属性“System.Windows.Controls.Control.Template” MainViewResource.xaml主窗口.xaml?

我正在使用 WPF MVVM 模式,并在 MainViewResource.xaml 中制作了控件的样式。

通常没有问题,但是当Slider中包含Control时,会出现以下错误。

''System.Windows.Style'' 不是属性 ''System.Windows.Controls.Control.Template'' 的有效值。

运行该应用程序没有问题,但 xaml 屏幕上不显示 Control

MainViewResource.xaml

<Style targettype="{x:Type Slider}" x:Key="SLD.INPUT">
    ...
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate targettype="{x:Type Slider}">
                <ControlTemplate.Resources>
                    ...
                </ControlTemplate.Resources>
                <Border x:Name="border">
                    <Grid>
                        <DockPanel>
                            <Border x:Name="PART_SelectionRange">
                                <Rectangle x:Name="sliderBar"/>
                            </Border>
                            <Border>
                                <Rectangle x:Name="PART_NegativeSelection"/>
                            </Border>
                        </DockPanel>
                        <Track x:Name="PART_Track">
                            <Track.Thumb>
                                <Thumb x:Name="thumb"/>
                            </Track.Thumb>
                        </Track>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding ElementName=thumb,Path=IsMouSEOver}" Value="true">
                        <Setter TargetName="sliderBar" Property="Fill" Value="{StaticResource LGB.SLD.FG.OVER}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ElementName=thumb,Path=IsDragging}" Value="true">
                        <Setter TargetName="sliderBar" Property="Fill" Value="{StaticResource LGB.SLD.FG.DRAG}"/>
                    </DataTrigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter TargetName="PART_SelectionRange" Property="Visibility" Value="Collapsed"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style targettype="{x:Type Control}" x:Key="CTL.INPUT">
    <Setter Property="Grid.Row" Value="1"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate targettype="{x:Type Control}">
                <ControlTemplate.Resources>
                    <Style targettype="{x:Type TextBlock}" x:Key="IN.CONTENT">
                        ...
                        <Setter Property="Text" Value="{Binding ElementName=slider2,Path=Value,Converter={StaticResource StringFormatConverter}}"/>
                    </Style>
                </ControlTemplate.Resources>
                <Grid>
                    <Grid.ColumnDeFinitions>
                        <ColumnDeFinition Width="Auto"/>
                        <ColumnDeFinition Width="*"/>
                    </Grid.ColumnDeFinitions>
                    <Slider x:Name="slider2"/>  // I guess here is the problem.
                    <TextBlock/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

主窗口.xaml

<Control/>

xaml 屏幕没有显示如下内容...

但是,当执行时,控件显示正确。

enter image description here

MainViewResource.xaml 正确注册到App.xaml,其他控件的样式没问题。仅当使用 Slider 的自定义样式作为 StaticResource 时才会出现问题。有谁知道我错过了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

关于WPF colorAnimation 边框画笔颜色抛出“System.Windows.Markup.XamlParseException”wpf textbox 边框颜色的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于.net – System.Drawing(GDI)vs System.Windows.Media(WPF)vs Direct2D DirectWrite WIC、ASP.NET Core 3.1:System.InvalidCastException:无法将“System.Int32”类型的对象转换为“System.Int64”类型、Automapper 错误:System.InvalidOperationException:'缺少从 System.String 到 System.Char 的映射、C# WPF 中的错误:“System.Windows.Style”不是属性“System.Windows.Controls.Control.Template” MainViewResource.xaml主窗口.xaml等相关内容,可以在本站寻找。

本文标签: