8,735
社区成员
虽然时间比较长了,我来回答一下吧,万一有人再碰到呢,重写DataPointStyle的模板具体代码:
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding FailCount}"/><!--需要多个就在这多写几个RowDefinition Height绑定比例就行-->
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="Red"/>
<Border Grid.Row="1" Background="Lime"/>
</Grid>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Top" Text="{Binding Num}" DockPanel.Dock="Top"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<TK:ColumnSeries DataContext="{Binding Counts}" Title="1" ItemsSource="{Binding States}" DependentValuePath="Num" IndependentValuePath="Name"/>
public class State:INotifyPropertyChanged
{
public State(string name)
{
this.Name = name;
}
string _Name;
public string Name { get { return _Name; } set { _Name = value; UpData(nameof(Name)); } }
double _Num;
public double Num { get { return _Num; }set { _Num = value; UpData(nameof(Num)); } }
public string FailCount { get; set; }=“0*”//这个值需要在小数后加*代表比例,比如”0.8*“,代表占显示总长的80%
public event PropertyChangedEventHandler PropertyChanged;
public void UpData(string name)
{
PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(name));
}
}
States是State的集合,要显示几个的话多写几个FailCount一样的属性前台绑定就行,如果要显示不固定数量那就把grid换成ItemsControl结合Viewbox写就行,但后台FailCount就需要是集合了,当然我相信会这么写的也就会直接自己重新开发个控件了*_*,不过不会也没关系,可以私信我,大家都是从不会到会一步步过来的嘛《^_^》