Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WinRT Xaml工具包更改列系列中的列宽_C#_Xaml_Uwp_Winrt Xaml Toolkit - Fatal编程技术网

C# WinRT Xaml工具包更改列系列中的列宽

C# WinRT Xaml工具包更改列系列中的列宽,c#,xaml,uwp,winrt-xaml-toolkit,C#,Xaml,Uwp,Winrt Xaml Toolkit,我正在测试WinRT Xaml工具包,有一个类似这样的问题。在列系列中,当我使用像第一张图片一样连续两个月的样本数据时,列宽自动计算得很好。但当我使用样本数据连续两个月,比如第二张图片(2月和9月),列宽有点失败。在第二张图片中,除了没有数据的月份的输入数据=0外,还有其他方法可以使列宽跨度像第一张图片一样整齐 这是我的密码: class Report { public string months { get; set; } public int value{ get; se

我正在测试WinRT Xaml工具包,有一个类似这样的问题。在列系列中,当我使用像第一张图片一样连续两个月的样本数据时,列宽自动计算得很好。但当我使用样本数据连续两个月,比如第二张图片(2月和9月),列宽有点失败。在第二张图片中,除了没有数据的月份的输入数据=0外,还有其他方法可以使列宽跨度像第一张图片一样整齐

这是我的密码:

class Report
{
    public string months { get; set; }
    public int value{ get; set; }
}

public MainPage()
{
    this.InitializeComponent();
    LoadChartContents();
}

private void LoadChartContents()
{
    List<Report> lstSource = new List<Report>();
    lstSource.Add(new Report() { months = "2", value= 10 });
    lstSource.Add(new Report() { months = "9", value= 15 });

    (LineChart.Series[0] as ColumnSeries).ItemsSource = lstSource;
    (LineChart.Series[0] as ColumnSeries).IndependentAxis = new LinearAxis{Minimum = 1,Maximum = 12,Orientation = AxisOrientation.X,Interval = 1};
}
课堂报告
{
公共字符串月份{get;set;}
公共int值{get;set;}
}
公共主页()
{
this.InitializeComponent();
LoadChartContents();
}
私有void LoadChartContents()
{
List lstSource=新列表();
添加(新报告(){months=“2”,值=10});
添加(新报告(){months=“9”,value=15});
(折线图系列[0]作为ColumnSeries)。ItemsSource=lstSource;
(线形图系列[0]作为柱状系列)。独立轴=新的线形轴{最小值=1,最大值=12,方向=轴方向.X,间隔=1};
}
Xaml


是否有其他方法可以使列宽像第一张图片一样整齐地跨越

可以通过重置样式来更改列宽。将
边框
元素的宽度更新为所需的宽度将影响列的宽度。代码如下:

<charting:Chart
    x:Name="Chart"
    Width="500"
    Margin="5"
    HorizontalAlignment="Center">
    <charting:ColumnSeries
        Title="Chart Name"
        DependentValuePath="value"
        IndependentValuePath="months">
        <charting:ColumnSeries.DataPointStyle>
            <Style TargetType="charting:ColumnDataPoint">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="charting:ColumnDataPoint">
                            <Border
                                x:Name="Root"
                                Width="20"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Opacity="0">
                                <Grid Background="{TemplateBinding Background}">
                                    <Rectangle
                                        x:Name="SelectionHighlight"
                                        Width="20"
                                        Fill="Red"
                                        Opacity="0" />
                                    <Rectangle
                                        x:Name="MouseOverHighlight"
                                        Width="20"
                                        Fill="White"
                                        Opacity="0" />
                                </Grid>
                                <ToolTipService.ToolTip>
                                    <ContentControl Content="{TemplateBinding FormattedDependentValue}" />
                                </ToolTipService.ToolTip>
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition GeneratedDuration="0:0:0.1" />
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="Normal" />
                                        <VisualState x:Name="MouseOver">
                                            <Storyboard>
                                                <DoubleAnimation
                                                    Duration="0"
                                                    Storyboard.TargetName="MouseOverHighlight"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="0.6" />
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="SelectionStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition GeneratedDuration="0:0:0.1" />
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="Unselected" />
                                        <VisualState x:Name="Selected">
                                            <Storyboard>
                                                <DoubleAnimation
                                                    Duration="0"
                                                    Storyboard.TargetName="SelectionHighlight"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="0.6" />
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="RevealStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition GeneratedDuration="0:0:0.001" />
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="Shown">
                                            <Storyboard>
                                                <DoubleAnimation
                                                    Duration="0"
                                                    Storyboard.TargetName="Root"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="1" />
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Hidden">
                                            <Storyboard>
                                                <DoubleAnimation
                                                    Duration="0"
                                                    Storyboard.TargetName="Root"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="0" />
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </charting:ColumnSeries.DataPointStyle>
    </charting:ColumnSeries>
</charting:Chart>
private void LoadChartContents()
{
    List<Report> lstSource = new List<Report>();
    for (int i = 1; i <= 12; i++)
    {
        if (i == 2)
        {
            lstSource.Add(new Report() { months = 2, value = 10 });
        }
        if (i == 9)
        {
            lstSource.Add(new Report() { months = 9, value = 15 });
        }
        else
        {
            lstSource.Add(new Report() { months = i, value = 0 });
        }
    }
    (Chart.Series[0] as ColumnSeries).ItemsSource = lstSource;
    //lstSource.Add(new Report() { months = 2, value = 10 });
    //lstSource.Add(new Report() { months = 9, value = 15 }); 
    //(Chart.Series[0] as ColumnSeries).IndependentAxis = new LinearAxis { Minimum = 1, Maximum = 12, Orientation = AxisOrientation.X, Interval = 1 };
}

虽然宽度可以根据样式更改,但我认为更好的方法是将集合的计数设置为自适应数字。正如您所知,宽度实际上可以自动计算,列之所以看起来如此宽,是因为它只有两条记录,平均12条记录的位置。我们可以创建12条记录,但只有2和9具有其他人可以设置为0的值。代码如下:

<charting:Chart
    x:Name="Chart"
    Width="500"
    Margin="5"
    HorizontalAlignment="Center">
    <charting:ColumnSeries
        Title="Chart Name"
        DependentValuePath="value"
        IndependentValuePath="months">
        <charting:ColumnSeries.DataPointStyle>
            <Style TargetType="charting:ColumnDataPoint">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="charting:ColumnDataPoint">
                            <Border
                                x:Name="Root"
                                Width="20"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Opacity="0">
                                <Grid Background="{TemplateBinding Background}">
                                    <Rectangle
                                        x:Name="SelectionHighlight"
                                        Width="20"
                                        Fill="Red"
                                        Opacity="0" />
                                    <Rectangle
                                        x:Name="MouseOverHighlight"
                                        Width="20"
                                        Fill="White"
                                        Opacity="0" />
                                </Grid>
                                <ToolTipService.ToolTip>
                                    <ContentControl Content="{TemplateBinding FormattedDependentValue}" />
                                </ToolTipService.ToolTip>
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition GeneratedDuration="0:0:0.1" />
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="Normal" />
                                        <VisualState x:Name="MouseOver">
                                            <Storyboard>
                                                <DoubleAnimation
                                                    Duration="0"
                                                    Storyboard.TargetName="MouseOverHighlight"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="0.6" />
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="SelectionStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition GeneratedDuration="0:0:0.1" />
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="Unselected" />
                                        <VisualState x:Name="Selected">
                                            <Storyboard>
                                                <DoubleAnimation
                                                    Duration="0"
                                                    Storyboard.TargetName="SelectionHighlight"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="0.6" />
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="RevealStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition GeneratedDuration="0:0:0.001" />
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="Shown">
                                            <Storyboard>
                                                <DoubleAnimation
                                                    Duration="0"
                                                    Storyboard.TargetName="Root"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="1" />
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Hidden">
                                            <Storyboard>
                                                <DoubleAnimation
                                                    Duration="0"
                                                    Storyboard.TargetName="Root"
                                                    Storyboard.TargetProperty="Opacity"
                                                    To="0" />
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </charting:ColumnSeries.DataPointStyle>
    </charting:ColumnSeries>
</charting:Chart>
private void LoadChartContents()
{
    List<Report> lstSource = new List<Report>();
    for (int i = 1; i <= 12; i++)
    {
        if (i == 2)
        {
            lstSource.Add(new Report() { months = 2, value = 10 });
        }
        if (i == 9)
        {
            lstSource.Add(new Report() { months = 9, value = 15 });
        }
        else
        {
            lstSource.Add(new Report() { months = i, value = 0 });
        }
    }
    (Chart.Series[0] as ColumnSeries).ItemsSource = lstSource;
    //lstSource.Add(new Report() { months = 2, value = 10 });
    //lstSource.Add(new Report() { months = 9, value = 15 }); 
    //(Chart.Series[0] as ColumnSeries).IndependentAxis = new LinearAxis { Minimum = 1, Maximum = 12, Orientation = AxisOrientation.X, Interval = 1 };
}
private void LoadChartContents()
{
List lstSource=新列表();

对于(int i=1;我确信有一种方法。请随意检查代码并建议更改。我正在尝试复制您的问题,但我不能。您可以上载吗?还是上传您的代码片段。此外,考虑签出。