简体   繁体   English

如何在Windows UWP App中制作径向量规

[英]how to make radial gauges in windows UWP app

im making a OBD scanner in Universal Windows platform (UWP) It has fake readouts right now for fuel level and air temperature Right now it just reads in text but i want to make it read in radial gauges 我在通用Windows平台(UWP)中制作了OBD扫描仪,它现在有虚假的读数,用于显示燃油液位和空气温度。现在,它只是读取文本,但我想使其在径向仪中读取

Can someone show me how to do so? 有人可以告诉我该怎么做吗? this is a personal project of mine so i appreciate the help 这是我的个人项目,非常感谢您的帮助

The radial gauges im trying to add: https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/radialgauge 试图添加的径向规: https : //docs.microsoft.com/zh-cn/windows/communitytoolkit/controls/radialgauge

my Xaml page so you can make changes to it or atleast see what im talking about : 我的Xaml页面,因此您可以对其进行更改,或者至少看到我在说什么:

<Page
x:Class="StandaloneEngineReadoutSystem.UwpApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:StandaloneEngineReadoutSystem.UwpApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Loaded="Page_Loaded">


<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock>Airtemperature</TextBlock>
    <TextBlock Text="{Binding AirTemp}"></TextBlock>

    <TextBlock>FuelLevel</TextBlock>
    <TextBlock Text="{Binding FuelLevel}"></TextBlock>
</StackPanel>

thanks in advance everyone! 预先感谢大家! if you need more information just let me know! 如果您需要更多信息,请告诉我!

how to make radial gauges in windows UWP app 如何在Windows UWP App中制作径向量规

For using RadialGauge , you need install Microsoft.Toolkit.Uwp.UI.Controls nuget package first. 要使用RadialGauge ,需要首先安装Microsoft.Toolkit.Uwp.UI.Controls nuget软件包。 Then make a RadialGauge instance in xaml page. 然后在xaml页面中创建RadialGauge实例。

<Grid>
    <controls:RadialGauge
        IsInteractive="True"
        Maximum="100"
        Minimum="0"
        NeedleBrush="DarkOrchid"
        NeedleWidth="2"
        ScaleTickBrush="Red"
        ScaleWidth="10"
        TickBrush="DarkOliveGreen"
        TickLength="10"
        TickSpacing="1"
        Unit="temp"
        Value="{x:Bind AirTemp, Mode=TwoWay}"
        />
</Grid>

Create bind property in code behind. 在后面的代码中创建绑定属性。

public sealed partial class MainPage : Page, INotifyPropertyChanged
{
    public MainPage()
    {
        this.InitializeComponent();
        SetFakeData();
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        if (PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

    }

    private int _airTemp;
    public int AirTemp
    {
        get
        {
            return _airTemp;
        }
        set
        {
            _airTemp = value;
            OnPropertyChanged();
        }
    }

    private void SetFakeData()
    {
        var timer = new DispatcherTimer();
        timer.Interval = TimeSpan.FromSeconds(0.5);
        timer.Tick += Timer_Tick;
        timer.Start();
    }

    private void Timer_Tick(object sender, object e)
    {
        do
        {
            AirTemp += 1;

        } while (AirTemp > 100);

    }
}

Finally, bind Value with AirTemp property. 最后,将ValueAirTemp属性绑定。 And I use a DispatcherTimer to make fake data. 我使用DispatcherTimer制作假数据。

Value="{x:Bind AirTemp, Mode=TwoWay}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM