在 XAML WP8 中添加 Slider 代码的位置
where to add the Slider code in XAML WP8
我在我的 XAML 页面中创建了一个图表,我想添加滑块以使用户能够缩放和平移 chart.I 正在关注 this tutorial,但我不确定下面的 Slider 代码应该放在 XAML 文件的哪一部分以启用缩放和平移:
<Slider x:Name="zoomoffset" Minimum="0" Maximum="1" />
<Slider x:Name="zoomoffset1" Minimum="0" Maximum="1" />
<Slider x:Name="zoomcoefficient" Minimum="0" Maximum="1" Value="1"/>
<Slider x:Name="zoomcoefficient1" Minimum="0" Maximum="1"Value="1"/>
这是完整的 XAML 文件:
<phone:PhoneApplicationPage
x:Class="MyApplication.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MyApplication"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:sparrow="clr-namespace:Sparrow.Chart;assembly=Sparrow.Chart.WP8.45"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<sparrow:SparrowChart Theme="Metro" AxisHeight="30">
<sparrow:SparrowChart.XAxis>
<sparrow:LinearXAxis ZoomCoefficient="{Binding Value,ElementName=zoomcoefficient}" ZoomOffset="{Binding Value,ElementName=zoomoffset}" />
</sparrow:SparrowChart.XAxis>
<sparrow:SparrowChart.YAxis>
<sparrow:LinearYAxis ZoomCoefficient="{Binding Value,ElementName=zoomcoefficient1}" ZoomOffset="{Binding Value,ElementName=zoomoffset1}" />
</sparrow:SparrowChart.YAxis>
</sparrow:SparrowChart>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
滑块代码应该粘贴到 XAMl 文件的哪一部分以便图表可以访问?
要使 ElementName
绑定生效,滑块必须位于同一 "namescope" 中。在这里,这基本上只是指在页面内部——所以无论你喜欢哪里。例如,将它们放在图表下方:
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<sparrow:SparrowChart Theme="Metro" AxisHeight="30">
<sparrow:SparrowChart.XAxis>
<sparrow:LinearXAxis ZoomCoefficient="{Binding Value,ElementName=zoomcoefficient}" ZoomOffset="{Binding Value,ElementName=zoomoffset}" />
</sparrow:SparrowChart.XAxis>
<sparrow:SparrowChart.YAxis>
<sparrow:LinearYAxis ZoomCoefficient="{Binding Value,ElementName=zoomcoefficient1}" ZoomOffset="{Binding Value,ElementName=zoomoffset1}" />
</sparrow:SparrowChart.YAxis>
</sparrow:SparrowChart>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Slider x:Name="zoomoffset" Minimum="0" Maximum="1" />
<Slider x:Name="zoomoffset1" Grid.Column="1" Minimum="0" Maximum="1" />
<Slider x:Name="zoomcoefficient" Grid.Column="2" Minimum="0" Maximum="1" Value="1"/>
<Slider x:Name="zoomcoefficient1" Grid.Column="3" Minimum="0" Maximum="1"Value="1"/>
</Grid>
</Grid>
我在我的 XAML 页面中创建了一个图表,我想添加滑块以使用户能够缩放和平移 chart.I 正在关注 this tutorial,但我不确定下面的 Slider 代码应该放在 XAML 文件的哪一部分以启用缩放和平移:
<Slider x:Name="zoomoffset" Minimum="0" Maximum="1" />
<Slider x:Name="zoomoffset1" Minimum="0" Maximum="1" />
<Slider x:Name="zoomcoefficient" Minimum="0" Maximum="1" Value="1"/>
<Slider x:Name="zoomcoefficient1" Minimum="0" Maximum="1"Value="1"/>
这是完整的 XAML 文件:
<phone:PhoneApplicationPage
x:Class="MyApplication.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MyApplication"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:sparrow="clr-namespace:Sparrow.Chart;assembly=Sparrow.Chart.WP8.45"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<sparrow:SparrowChart Theme="Metro" AxisHeight="30">
<sparrow:SparrowChart.XAxis>
<sparrow:LinearXAxis ZoomCoefficient="{Binding Value,ElementName=zoomcoefficient}" ZoomOffset="{Binding Value,ElementName=zoomoffset}" />
</sparrow:SparrowChart.XAxis>
<sparrow:SparrowChart.YAxis>
<sparrow:LinearYAxis ZoomCoefficient="{Binding Value,ElementName=zoomcoefficient1}" ZoomOffset="{Binding Value,ElementName=zoomoffset1}" />
</sparrow:SparrowChart.YAxis>
</sparrow:SparrowChart>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
滑块代码应该粘贴到 XAMl 文件的哪一部分以便图表可以访问?
要使 ElementName
绑定生效,滑块必须位于同一 "namescope" 中。在这里,这基本上只是指在页面内部——所以无论你喜欢哪里。例如,将它们放在图表下方:
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<sparrow:SparrowChart Theme="Metro" AxisHeight="30">
<sparrow:SparrowChart.XAxis>
<sparrow:LinearXAxis ZoomCoefficient="{Binding Value,ElementName=zoomcoefficient}" ZoomOffset="{Binding Value,ElementName=zoomoffset}" />
</sparrow:SparrowChart.XAxis>
<sparrow:SparrowChart.YAxis>
<sparrow:LinearYAxis ZoomCoefficient="{Binding Value,ElementName=zoomcoefficient1}" ZoomOffset="{Binding Value,ElementName=zoomoffset1}" />
</sparrow:SparrowChart.YAxis>
</sparrow:SparrowChart>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Slider x:Name="zoomoffset" Minimum="0" Maximum="1" />
<Slider x:Name="zoomoffset1" Grid.Column="1" Minimum="0" Maximum="1" />
<Slider x:Name="zoomcoefficient" Grid.Column="2" Minimum="0" Maximum="1" Value="1"/>
<Slider x:Name="zoomcoefficient1" Grid.Column="3" Minimum="0" Maximum="1"Value="1"/>
</Grid>
</Grid>