WPF备忘录(4)打个勾画个叉娱乐下
<Path Grid.Column="2" Data="M43,5 L20,40 20,40 0,20 6,15 18,26 37,7 43,5 z" Fill="Green" Margin="5" Stretch="Fill" HorizontalAlignment="Right"/>
<Path Margin="5" Data="M50,25 L25,50 M25,25 50,50" Fill="#FFF4F4F5" Stretch="Fill" Stroke="Red" StrokeThickness="8" HorizontalAlignment="Right"/>
好了,看这个红叉叉打的,下面先来一条异常:
1.在“System.Windows.Baml2006.DeferredBinaryDeserializerExtension”上提供值时引发了异常
上图:
这个问题我纠结了半天查了好多资料而不可得,总以为是数据绑定之类的错误,最后才发现是一个TextBlock的背景颜色值设错了。
血淋淋的教训啊浪费了半天时间就因为自己的大意。遇到这种问题如果实在找不错问题,就一个一个剔除控件,找到出问题的控件。
2.一个自定义ListView模板,看你是否用的上
<Grid> <ListView Name="LV_Test" SelectionMode="Multiple" Background="{x:Null}"> <ListView.Template> <ControlTemplate> <Border CornerRadius="10" BorderBrush="RoyalBlue" BorderThickness="5"> <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" > <ItemsPresenter /> </ScrollViewer> </Border> </ControlTemplate> </ListView.Template> <ListView.ItemsPanel> <ItemsPanelTemplate> <WrapPanel IsItemsHost="True"/> </ItemsPanelTemplate> </ListView.ItemsPanel> <ListView.ItemContainerStyle> <Style TargetType="{x:Type ListViewItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListViewItem}"> <Border Name="BD_Collector" CornerRadius="5" Background="DarkSeaGreen" Width="auto" Height="30" Margin="5"> <StackPanel Orientation="Horizontal"> <Label Content="{Binding XH}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="13" /> <Label Content="{Binding time}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="13" /> </StackPanel> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="BD_Collector" Property="Background" Value="YellowGreen" /> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter TargetName="BD_Collector" Property="Background" Value="DarkGreen" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ListView.ItemContainerStyle> <ListView.View> <GridView> <GridViewColumn Header="序号" DisplayMemberBinding="{Binding XH}" Width="100"/> <GridViewColumn Header="日期" DisplayMemberBinding="{Binding time}" Width="140"/> <GridViewColumn Header="项目" DisplayMemberBinding="{Binding CostItem}" Width="100"/> <GridViewColumn Header="金额" DisplayMemberBinding="{Binding CostMoney}" Width="100"/> </GridView> </ListView.View> </ListView> </Grid>
上图:
未完待续……