Вот моя код:
Построение файла Xaml:
Код: Выделить всё
Код: Выделить всё
namespace MyApp.ViewModel.Components
{
public class PlotViewModel : ObservableObject,IDisposable
{
// Inside your PlotViewModel class
private UdpClient _udpClient;
private NetworkStream _networkStream;
private DispatcherTimer _timer;
private bool _isPaused;
private Slider _wavelengthSlider;
private TextBlock _selectedWavelengthLabel;
private bool _isTracking;
private double _wavelengthSliderValue;
public PlotViewModel()
{
InitializeRenderingLoop();
// Initialize SpectralPlotModel
SpectralPlotModel = new PlotModel
{
Title = "Sweep",
Background = OxyColors.Transparent,
TextColor = OxyColors.White,
PlotAreaBorderColor = OxyColors.White
};
SpectralPlotModel.Axes.Add(new LinearAxis
{
Position = AxisPosition.Bottom,
Title = "Wavelength",
TitleColor = OxyColors.White,
AxislineColor = OxyColors.White,
TextColor = OxyColors.White,
StringFormat = "0.###",
Minimum = 1546,
Maximum = 1558
});
SpectralPlotModel.Axes.Add(new LinearAxis
{
Position = AxisPosition.Left,
Title = "Units",
TitleColor = OxyColors.White,
AxislineColor = OxyColors.White,
TextColor = OxyColors.White,
StringFormat = "0.###",
Minimum = 0,
Maximum = 5
});
SpectralPlotModel.Series.Add(new LineSeries
{
Title = "Data",
Color = OxyColors.White,
MarkerFill = OxyColors.White,
MarkerType = MarkerType.None,
LineStyle = LineStyle.Solid,
StrokeThickness = 2,
});
// Create and add LineAnnotation directly
SpectralPlotModel.Annotations.Add(new LineAnnotation
{
Color = OxyColors.Red,
LineStyle = LineStyle.Solid,
StrokeThickness = 5,
Type = LineAnnotationType.Vertical,
X = 1546,
Text = "Pick a Spectrum",
MinimumX = 1546,
MaximumX = 1558,
MinimumY = 0,
MaximumY = 5
});
}
public void UpdateRedLine(double WavelengthSliderValue)
{
var redLineAnnotation = SpectralPlotModel.Annotations.FirstOrDefault(a => a is LineAnnotation) as LineAnnotation;
if (redLineAnnotation != null)
{
redLineAnnotation.X = WavelengthSliderValue;
SpectralPlotModel.InvalidatePlot(true);
}
}
Код: Выделить всё
Код: Выделить всё
namespace MyApp.ViewModel.Screens
{
public class AEViewModel : ObservableObject
{
private PlotViewModel _plotViewModel;
private double _wavelengthSliderValue;
public AEViewModel()
{
_plotViewModel = new PlotViewModel();
}
public double WavelengthSliderValue
{
get => _wavelengthSliderValue;
set
{
if (_wavelengthSliderValue != value)
{
_wavelengthSliderValue = value;
OnPropertyChanged();
_plotViewModel.WavelengthSliderValue = value;
_plotViewModel.UpdateRedLine(_wavelengthSliderValue);
}
}
}
}
}
Что-то не так с re - триггер рендеринга.
Подробнее здесь: https://stackoverflow.com/questions/790 ... the-slider