Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Converter in DataTemplate

$
0
0

I have a datatemplate in a separate xaml file and I cannot get the converter to work. What needs be done? Thanks.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:viewmodelbase="clr-namespace:MyApp.ViewModel.Base"
             xmlns:viewmodel="clr-namespace:MyApp.ViewModel"
             x:DataType="viewmodel:SharingViewModel"
             x:Class="MyApp.View.SharingPage"
             x:Name="sharingpage"
             Visual="Material" >
    <ContentPage.Resources>
        <viewmodelbase:InverseBoolConverter x:Key="inverter"/>
        <ResourceDictionary Source="DataTemplate\MyViewTemplate.xaml"  />
    </ContentPage.Resources>

    <ContentPage.Content>

        <StackLayout>
             <Button Margin="0,10,0,10" Text="Scan QR Code" BackgroundColor="Orange"
                     WidthRequest="150"  BorderRadius="60" VerticalOptions="Center" 
                     HorizontalOptions="Center"
                    Clicked="OnButtonClicked" >
             </Button>

            <ListView x:Name="DeviceListView" SeparatorVisibility="Default" 
                  HorizontalOptions="FillAndExpand" 
                  VerticalOptions="FillAndExpand" 
                  RowHeight="90" 
                  ItemTapped="OnItemTapped"
                  ItemSelected="OnItemSelected"
                  ItemsSource="{Binding Person}" 
                  ItemTemplate="{StaticResource MyViewTemplate}">

            </ListView>



        </StackLayout>
    </ContentPage.Content>
</ContentPage> 

MyViewTemplate.xaml

<?xml version="1.0" encoding="UTF-8"?>
<?xaml-comp compile="true" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                >



    <DataTemplate x:Key="MyViewTemplate"   >
        <ViewCell>
            <ViewCell.View>
                <StackLayout Margin="2,4,4,4" VerticalOptions="FillAndExpand" >
                    <Frame  Padding="2"  HasShadow="False" BorderColor="LightGray"  CornerRadius="15" IsClippedToBounds="True" VerticalOptions="FillAndExpand">
                        <Grid  Opacity = "{Binding Opacity}" >
                            <Grid.ColumnDefinitions >
                                <ColumnDefinition Width="8"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="2*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.15*"/>
                                <RowDefinition Height="0.7*"/>
                                <RowDefinition Height="0.15*"/>
                            </Grid.RowDefinitions>
                            <Image Source="{Binding Image}"  Aspect="AspectFit" Grid.Row="1" Grid.Column="1"/>
                            <StackLayout  Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" IsVisible="{Binding IsEnable}" >
                                <Label Text="{Binding Name}" VerticalTextAlignment="Center" FontSize="20"   />
                            </StackLayout>
                            <StackLayout  Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2" IsVisible="{Binding IsEnable, Converter={Resource inverter}  }" >
                                <Label Text="No Found" VerticalTextAlignment="Center" FontSize="20"   />
                            </StackLayout> 
                        </Grid>
                    </Frame>
                </StackLayout>
            </ViewCell.View>
        </ViewCell>
    </DataTemplate>
</ResourceDictionary>

Viewing all articles
Browse latest Browse all 204402

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>