[WPF系列] 高级 调试

本文解决了一个在WPF应用程序中使用ImageBrush时出现的TypeConverter异常问题,并提供了一种正确的图片资源引用方式。此外,还讨论了如何区分Width与MaxWidth属性,以及解决Label控件字体颜色无法更改的问题。

调试工具

image

 

ImageBrush出现TypeConverter问题

'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '49' and line position '38'

 

Assuming the image is:

  • Included in your project
  • It's in a folder named "Images"
  • The build action for the image is set to "Resource" (should be the default)

You can reference it like this:

<ImageBrush ImageSource=
   "pack://application:,,,/YourProjectName;component/Images/wood1_1000X1000.jpg";

 

This fixed the issue, I put the image in the project folder whithout including it in the project itself.

 

 

Width与MaxWidth的区别

当你所要控制的对象,宽度或者高度值总是变化,而不是你想要指定的固定值,那么很有可能设置成了MaxHeight(MaxWidth)

 

Label等其他控件字体颜色修改不了

这个是很有可能是定义一个全局的TextBook,且没有指定该Style的Key值。导致Label等控件的字体大小颜色无法修改。

 

模板虽好但莫随意使用

实例:试想下如果你将如下代码定义到你到的Resource中会发生什么奇妙的现象了?

 <DataTemplate DataType="{x:Type system:String}">
            <StackPanel>
                <Image Source="{Binding }" MinHeight="500" MaxHeight="600" MaxWidth="800" />
            </StackPanel>
        </DataTemplate>
ToolTip会变成这样,Button会变成一条线。

WPFToolTips

转载于:https://www.cnblogs.com/HQFZ/p/4211336.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值