-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72c619b
commit e2632a8
Showing
8 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/WPFDevelopers.Samples.Shared/ExampleViews/ChartPieExample.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<UserControl | ||
x:Class="WPFDevelopers.Samples.ExampleViews.ChartPieExample" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:controls="clr-namespace:WPFDevelopers.Samples.Controls" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers" | ||
d:DesignHeight="450" | ||
d:DesignWidth="800" | ||
mc:Ignorable="d"> | ||
<controls:CodeViewer> | ||
<Grid Background="{DynamicResource WD.BackgroundSolidColorBrush}"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> | ||
<Border | ||
Height="300" | ||
Margin="30,0" | ||
Background="{DynamicResource WD.BackgroundSolidColorBrush}"> | ||
<wd:ChartPie Datas="{Binding Datas, RelativeSource={RelativeSource AncestorType=local:ChartPieExample}}" /> | ||
</Border> | ||
</ScrollViewer> | ||
<Button | ||
Grid.Row="1" | ||
Width="200" | ||
VerticalAlignment="Bottom" | ||
Click="Button_Click" | ||
Content="刷新" | ||
Style="{StaticResource WD.PrimaryButton}" /> | ||
</Grid> | ||
<controls:CodeViewer.SourceCodes> | ||
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/ChartPieExample.xaml" CodeType="Xaml" /> | ||
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/ChartPieExample.xaml.cs" CodeType="CSharp" /> | ||
</controls:CodeViewer.SourceCodes> | ||
</controls:CodeViewer> | ||
</UserControl> |
68 changes: 68 additions & 0 deletions
68
src/WPFDevelopers.Samples.Shared/ExampleViews/ChartPieExample.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.NetworkInformation; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar; | ||
|
||
namespace WPFDevelopers.Samples.ExampleViews | ||
{ | ||
/// <summary> | ||
/// ChartPieExample.xaml 的交互逻辑 | ||
/// </summary> | ||
public partial class ChartPieExample : UserControl | ||
{ | ||
public IEnumerable<KeyValuePair<string, double>> Datas | ||
{ | ||
get { return (IEnumerable<KeyValuePair<string, double>>)GetValue(DatasProperty); } | ||
set { SetValue(DatasProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty DatasProperty = | ||
DependencyProperty.Register("Datas", typeof(IEnumerable<KeyValuePair<string, double>>), typeof(ChartPieExample), new PropertyMetadata(null)); | ||
|
||
private Dictionary<string, IEnumerable<KeyValuePair<string, double>>> keyValues = new Dictionary<string, IEnumerable<KeyValuePair<string, double>>>(); | ||
private int _index = 0; | ||
public ChartPieExample() | ||
{ | ||
InitializeComponent(); | ||
var models1 = new[] | ||
{ | ||
new KeyValuePair<string, double>("Mon", 120), | ||
new KeyValuePair<string, double>("Tue", 530), | ||
new KeyValuePair<string, double>("Wed", 1060), | ||
new KeyValuePair<string, double>("Thu", 140), | ||
new KeyValuePair<string, double>("Fri", 8000.123456) , | ||
new KeyValuePair<string, double>("Sat", 200) , | ||
new KeyValuePair<string, double>("Sun", 300) , | ||
}; | ||
var models2 = new[] | ||
{ | ||
new KeyValuePair<string, double>("Bing", 120), | ||
new KeyValuePair<string, double>("Google", 170), | ||
new KeyValuePair<string, double>("Baidu", 30), | ||
new KeyValuePair<string, double>("Github", 200), | ||
new KeyValuePair<string, double>("Stack Overflow", 100) , | ||
new KeyValuePair<string, double>("Runoob", 180) , | ||
new KeyValuePair<string, double>("Open AI", 90) , | ||
new KeyValuePair<string, double>("Open AI2", 93) , | ||
new KeyValuePair<string, double>("Open AI3", 94) , | ||
new KeyValuePair<string, double>("Open AI4", 95) , | ||
}; | ||
keyValues.Add("1", models1); | ||
keyValues.Add("2", models2); | ||
Datas = models1; | ||
} | ||
|
||
private void Button_Click(object sender, RoutedEventArgs e) | ||
{ | ||
_index++; | ||
if (_index >= keyValues.Count) | ||
{ | ||
_index = 0; | ||
} | ||
Datas = keyValues.ToList()[_index].Value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.