Created
March 2, 2022 22:05
-
-
Save odyright/18e5b8c3bde14fdb0c39de7b9d0d09b8 to your computer and use it in GitHub Desktop.
NullToVisibility
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
// From https://github.com/Dylan-H/NotePadUWP/ | |
#include "pch.h" | |
#include "EmptyObjectToObjectConverter.h" | |
#include "ConverterTools.h" | |
namespace winrt::NotePad::implementation | |
{ | |
DependencyProperty EmptyObjectToObjectConverter::_NotEmptyValueProperty = | |
DependencyProperty::Register(L"NotEmptyValue", winrt::xaml_typename<IInspectable>(), winrt::xaml_typename<NotePad::EmptyObjectToObjectConverter>(), PropertyMetadata(nullptr)); | |
DependencyProperty EmptyObjectToObjectConverter::_EmptyValueProperty = | |
DependencyProperty::Register(L"EmptyValue", winrt::xaml_typename<IInspectable>(), winrt::xaml_typename<NotePad::EmptyObjectToObjectConverter>(), PropertyMetadata(nullptr)); | |
IInspectable EmptyObjectToObjectConverter::Convert(IInspectable const& value, Interop::TypeName const& targetType, IInspectable const& parameter, hstring const& language) | |
{ | |
auto isEmpty = CheckValueIsEmpty(value); | |
// Negate if needed | |
if (winrt::NotePad::ConverterTools::TryParseBool(parameter)) | |
{ | |
isEmpty = !isEmpty; | |
} | |
return winrt::NotePad::ConverterTools::Convert(isEmpty ? EmptyValue() : NotEmptyValue(), targetType); | |
} | |
IInspectable EmptyObjectToObjectConverter::ConvertBack(IInspectable const& value, Interop::TypeName const& targetType, IInspectable const& parameter, hstring const& language) | |
{ | |
throw hresult_not_implemented(); | |
} | |
} |
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
// From https://github.com/Dylan-H/NotePadUWP/ | |
#pragma once | |
#include "EmptyObjectToObjectConverter.g.h" | |
namespace winrt::NotePad::implementation | |
{ | |
using namespace winrt::Windows::UI::Xaml; | |
using namespace winrt::Windows::Foundation; | |
struct EmptyObjectToObjectConverter : EmptyObjectToObjectConverterT<EmptyObjectToObjectConverter> | |
{ | |
EmptyObjectToObjectConverter() = default; | |
IInspectable NotEmptyValue() { { return GetValue(_NotEmptyValueProperty); } }; | |
void NotEmptyValue(IInspectable const& value) { SetValue(_NotEmptyValueProperty, value); }; | |
IInspectable EmptyValue() { return GetValue(_EmptyValueProperty); }; | |
void EmptyValue(IInspectable const& value) { SetValue(_EmptyValueProperty, value); }; | |
IInspectable Convert(IInspectable const& value, Interop::TypeName const& targetType, IInspectable const& parameter, hstring const& language); | |
IInspectable ConvertBack(IInspectable const& value, Interop::TypeName const& targetType, IInspectable const& parameter, hstring const& language); | |
virtual bool CheckValueIsEmpty(IInspectable value) | |
{ | |
return value == nullptr; | |
} | |
static DependencyProperty NotEmptyValueProperty() { return _NotEmptyValueProperty; }; | |
static DependencyProperty EmptyValueProperty() { return _EmptyValueProperty; }; | |
private: | |
static DependencyProperty _NotEmptyValueProperty; | |
static DependencyProperty _EmptyValueProperty; | |
}; | |
} | |
namespace winrt::NotePad::factory_implementation | |
{ | |
struct EmptyObjectToObjectConverter : EmptyObjectToObjectConverterT<EmptyObjectToObjectConverter, implementation::EmptyObjectToObjectConverter> | |
{ | |
}; | |
} |
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
// From https://github.com/Dylan-H/NotePadUWP/ | |
namespace NotePad | |
{ | |
[default_interface] | |
runtimeclass EmptyObjectToObjectConverter : Windows.UI.Xaml.DependencyObject, Windows.UI.Xaml.Data.IValueConverter | |
{ | |
EmptyObjectToObjectConverter(); | |
static Windows.UI.Xaml.DependencyProperty NotEmptyValueProperty{ get; }; | |
static Windows.UI.Xaml.DependencyProperty EmptyValueProperty{ get; }; | |
Object NotEmptyValue; | |
Object EmptyValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment