rsp
rsp

Reputation: 649

UWP: Lifecycle event when the content on elements becomes available when content is set using async

I have UWP page and it is using data binding to set content on xaml elements (texts, buttons, image). I am setting the content using async calls (getting content from internet). In the page's c'tor, I subscribed to Loaded event. And obtained button using FindName() method on the control. Got the content on the button and it is coming as empty. I am assuming it is because I am setting content using async calls and when I debugged using breakpoints, it is indeed the case. The content is set after Loaded event is fired.

So my question is - what is the event fired when content on xaml elements becomes available?

Below is my code:

void ValuePropControl::ControlLoaded(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e)
{
    auto b{ sender.as<ValueProp::ValuePropControl>() };
    auto buttttton = b.FindName(L"OpenFamilyAppButton");
    auto bbttnn = buttttton.as<Windows::UI::Xaml::Controls::Button>();
    auto contentt = bbttnn.Content();
    auto texxxt = winrt::unbox_value<hstring>(contentt);
}

Variable 'texxxt' is empty.

<Grid
    Grid.Column="0"
    CornerRadius="3">
    <Button
        x:Name="OpenFamilyAppButton"
        MinWidth="118"
        MinHeight="30"
        HorizontalAlignment="Left"
        HorizontalContentAlignment="Center"
        VerticalContentAlignment="Center"
        AutomationProperties.Name="{x:Bind ViewModel.PrimaryActionAutomationName, Mode=OneWay}"
        BorderThickness="1"
        Click="{x:Bind ViewModel.InvokePrimaryAction}"
        Content="{x:Bind ViewModel.PrimaryAction, Mode=OneWay}"
        CornerRadius="3"
        Style="{StaticResource AccentButtonStyle}" />
</Grid>

Upvotes: 0

Views: 65

Answers (0)

Related Questions