Sending dependency property via xaml to converter
Posted: 13 Nov 2024, 08:53
In my view i have several dependency properties and depends on their values, i want to update another value by using converter
Here the properties declaration:
Their registration
Their usage in the xaml in the converter
Here the converter that receives the dependency properties
After changing the progress value in the converter I get a garbage value of min and max If I don't change the default min and max value from the outside, how can I solve this problem?
Here the properties declaration:
Code: Select all
const Noesis::DependencyProperty *SlideButtonUserControlView::ProgressValueProperty;
const Noesis::DependencyProperty *SlideButtonUserControlView::MaxProgressValueProperty;
const Noesis::DependencyProperty *SlideButtonUserControlView::MinProgressValueProperty;
Code: Select all
auto onProgressValueChanged = [](DependencyObject* d, const Noesis::DependencyPropertyChangedEventArgs& e) {
const auto control = Noesis::DynamicCast<SlideButtonUserControlView *>(d);
const auto new_value = *static_cast<const int *>(e.newValue);
if (new_value == control->getMaxProgressValue()) {
control->SetState(eSlideButtonState::E_COMPLETED);
}
};
data->RegisterProperty<int>(ProgressValueProperty, "ProgressValue", Noesis::PropertyMetadata::Create(int(0),
Noesis::PropertyChangedCallback(onProgressValueChanged)));
data->RegisterProperty<int>(MinProgressValueProperty, "MinProgressValue", Noesis::PropertyMetadata::Create(int(0)));
data->RegisterProperty<int>(MaxProgressValueProperty, "MaxProgressValue", Noesis::PropertyMetadata::Create(int(100)));
Code: Select all
<local:cSlideButtonProgressConverter x:Key="SlideButtonProgressConverter"/>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="InProgressLeftColorStop"
Storyboard.TargetProperty="Offset">
<DiscreteDoubleKeyFrame KeyTime="0">
<DiscreteDoubleKeyFrame.Value>
<MultiBinding Converter="{StaticResource SlideButtonProgressConverter}" ConverterParameter="LeftColorStop">
<Binding ElementName="SlideButtonControl" Path="ProgressValue" />
<Binding ElementName="SlideButtonControl" Path="MinProgressValue" />
<Binding ElementName="SlideButtonControl" Path="MaxProgressValue" />
</MultiBinding>
</DiscreteDoubleKeyFrame.Value>
</DiscreteDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
Code: Select all
bool cSlideButtonProgressConverter::TryConvert(Noesis::ArrayRef<Noesis::BaseComponent *> values, const Noesis::Type *targetType,
Noesis::BaseComponent *param, Noesis::Ptr<Noesis::BaseComponent> &result) {
NS_UNUSED(targetType);
if (values.Size() == 3 && param != nullptr) {
const auto progress_value = Noesis::Boxing::Unbox<int>(values[0]);
const auto min_value = Noesis::Boxing::Unbox<int>(values[1]);
const auto max_value = Noesis::Boxing::Unbox<int>(values[2]);
Noesis::String conv_param = Noesis::Boxing::Unbox<Noesis::String>(param);
float scale = (progress_value - min_value) / (max_value - min_value);
if (conv_param == "LeftColorStop") {
scale += default_left_shift;
} else if (conv_param != "RightColorStop") {
result = Noesis::Boxing::Box(0.0f); // Default case
return true;
}
result = Noesis::Boxing::Box(scale);
return true;
}
return false;
}