1
Vote

design time issues

description

Getting loads of issues design time, mostly about DisplayInformation::GetForCurrentView happening on wrong thread. Im not a c++ guy at all, but eventually an obvious solution appeared:
ShaderContentControl::ShaderContentControl() : m_renderedElementDirty(true), m_ignoreNextLayoutUpdate(false), m_extraPadSize(0, 0)
{
    bool isDesignMode = DesignMode::DesignModeEnabled;

    if (!isDesignMode && !m_gfx)
    {
        m_gfx = make_shared<GraphicsDeviceContext>();
    }

    auto controlTemplate = safe_cast<ControlTemplate^>(XamlReader::Load(ref new String(CONTENT_CONTROL_TEMPLATE)));

    Template = controlTemplate;

    

    m_loadedEventToken   = Loaded   += ref new RoutedEventHandler(this, &ShaderContentControl::OnLoaded);
    m_unloadedEventToken = Unloaded += ref new RoutedEventHandler(this, &ShaderContentControl::OnUnloaded);

    CoreApplication::Suspending            += ref new EventHandler<SuspendingEventArgs^>             (this, &ShaderContentControl::OnSuspending);
    CompositionTarget::SurfaceContentsLost += ref new EventHandler<Platform::Object^>                (this, &ShaderContentControl::OnSurfaceContentsLost);

    if (!isDesignMode && !m_gfx)
    {
        auto displayInformation = DisplayInformation::GetForCurrentView();
        displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^, Object^>(this, &ShaderContentControl::OnDpiChanged);
    }
}
what this boils down to is just not setting up the DPI changed stuff when in design time, which should be ok. You dont see the effect in design time, but you do get to see your xaml without evil [x]'s everywhere.

comments