На MainWindow.xaml.cs Я определил:связывание свойства из другого файла CS с преобразователем WPF
private int _currentStep = 1;
public int CurrentStep
{
get
{
return _currentStep;
}
set
{
_currentStep = value;
NotifyPropertyChanged("CurrentStep");
}
}
private void NotifyPropertyChanged(string info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public event PropertyChangedEventHandler PropertyChanged;
И я также обновить CurrentStep в одном файле.
На MessageWithProgressBar.xaml Я определил:
<Window x:Class="Db.MessageWithProgressBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Db"
mc:Ignorable="d"
Title="DB Processing" Height="150" Width="300" Background="{DynamicResource {x:Static SystemColors.GradientInactiveCaptionBrushKey}}">
<Window.Resources>
<local:currentStepToProgressValue x:Key="stepToProgress"/>
</Window.Resources>
<Grid DataContext="{Binding RelativeSource={RelativeSource AncestorType=Window}}">
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Name="title" Content="Please wait while processing.." FontSize="17.333"/>
</Grid>
<Grid Grid.Row="1" Margin="0,0,0,20">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ProgressBar Name="progress" IsIndeterminate="True" Value="{Binding CurrentStep, Converter={StaticResource stepToProgress}}" />
</Grid>
</Grid>
ошибка я получил во время выполнения является:
BindingExpression path error: 'CurrentStep' property not found on 'object' ''String' (HashCode=1137317725)'. BindingExpression:Path=CurrentStep; DataItem='String' (HashCode=1137317725); target element is 'ProgressBar' (Name='progress'); target property is 'Value' (type 'Double')
Любая помощь?
Спасибо!
Почему вы пытаетесь связать индикатор выполнения с собственностью в другом окне? Почему бы просто не вводить значение при показе 'MessageWithProgressBar'? Если значение не может быть введено в MessageWithProgressBar, тогда подумайте о том, чтобы вместо этого выполнить работу как делегат, чтобы его можно было зафиксировать и измерить в MessageWithProgressBar. – slugster
@slugster В MainWindow.xaml.cs Я обрабатываю задание, и, обрабатывая задание, я хочу поднять другое окно (которое отображает прогрессную панель) в качестве потока, а значение прогресса будет обновляться согласно шагу задания, который устанавливается, как указано выше в MainWindow. xaml.cs – Programmer
Я догадался, что вы пытаетесь сделать, и вы идете по нему не так. Вам нужна служба диалога, есть много примеров там с разной степенью сложности. Вот два предыдущих вопроса SO, которые помогут вам начать: [* Хорошая или плохая практика для Dialogs в wpf с MVVM? *] (Http://stackoverflow.com/q/3801681/109702), [* Стандартный подход для запуска диалогов/Ребенок из приложения WPF с использованием MVVM *] (http://stackoverflow.com/q/17308945/109702) – slugster