Share via

ignoring margin on dektop

Eduardo Gomez Romero 1,375 Reputation points
2024-10-11T17:07:37.33+00:00

In my Maui app, I have a customBorderStyle, that my

DeskTopTemplate

is ignoring completely

  <ContentPage.Resources>
      <DataTemplate
          x:Key="PhoneTemplate"
          x:DataType="{x:Null}">
          <SwipeView Threshold="300">
              <SwipeView.RightItems>
                  <SwipeItems Mode="Execute">
                      <SwipeItem
                          BackgroundColor="{AppThemeBinding Dark={x:StaticResource SwipeDark},
                                                            Light={x:StaticResource SwipeLight}}"
                          Command="{Binding DeleteTurbineCommand, Source={x:RelativeSource AncestorType={x:Type vm:TurbinesCollectionPageViewModel}}}"
                          CommandParameter="{Binding Source={x:Reference BorderContaier}}">
                          <SwipeItem.IconImageSource>
                              <FontImageSource
                                  FontFamily="ma"
                                  Glyph="{x:Static constant:MaterialFonts.Delete}" />
                          </SwipeItem.IconImageSource>
                      </SwipeItem>
                  </SwipeItems>
              </SwipeView.RightItems>
              <Border
                  x:Name="BorderContaier"
                  Style="{x:StaticResource CommonBorderStyle}">
                  <controls:TurbineData
                      TurbineAddres="{Binding Turbine.Address}"
                      TurbineCreationDate="{Binding Turbine.LocalizedInstalationDateTime}"
                      TurbineName="{Binding Turbine.Name}" />
              </Border>
          </SwipeView>
      </DataTemplate>
      <DataTemplate
          x:Key="DeskTopTemplate"
          x:DataType="{x:Null}">
          <Border
              x:Name="borderContainer"
              Style="{x:StaticResource CommonBorderStyle}">
              <Grid
                  x:Name="GridContainer"
                  ColumnDefinitions="*,*">
                  <controls:TurbineData
                      Grid.ColumnSpan="2"
                      TurbineAddres="{Binding Turbine.Address}"
                      TurbineCreationDate="{Binding Turbine.LocalizedInstalationDateTime}"
                      TurbineName="{Binding Turbine.Name}" />
                  <Button
                      Grid.RowSpan="3"
                      Grid.Column="1"
                      Command="{Binding DeleteTurbineCommand, Source={x:RelativeSource AncestorType={x:Type vm:TurbinesCollectionPageViewModel}}}"
                      CommandParameter="{Binding Source={x:Reference borderContainer}}"
                      HeightRequest="{Binding Height, Source={x:Reference GridContainer}}"
                      IsVisible="{Binding IsDeleteButtonVisible, Source={x:RelativeSource AncestorType={x:Type vm:TurbinesCollectionPageViewModel}}}"
                      Style="{x:StaticResource DeleteButtonStyle}"
                      Text="{x:Static constant:MaterialFonts.Delete}" />
              </Grid>
              <Border.GestureRecognizers>
                  <PointerGestureRecognizer PointerEnteredCommand="{Binding MouseEnterCommand, Source={x:RelativeSource AncestorType={x:Type vm:TurbinesCollectionPageViewModel}}}" />
                  <PointerGestureRecognizer PointerExitedCommand="{Binding MouseLeaveCommand, Source={x:RelativeSource AncestorType={x:Type vm:TurbinesCollectionPageViewModel}}}" />
              </Border.GestureRecognizers>
          </Border>
      </DataTemplate>
      <local:DeviceDataTemplateSelector
          x:Key="SelectDataTemplateSelector"
          DeskTopTemplate="{StaticResource DeskTopTemplate}"
          PhoneTemplate="{StaticResource PhoneTemplate}" />
  </ContentPage.Resources>
  <Grid>
      <CollectionView
          x:Name="TurbineCollection"
          Margin="10"
          ItemTemplate="{StaticResource SelectDataTemplateSelector}"
          ItemsSource="{Binding Turbines}" />
  <Style
     x:Key="CommonBorderStyle"
     TargetType="Border">
     <Setter Property="StrokeShape" Value="RoundRectangle 10" />
     <Setter Property="Margin" Value="0,10,0,0" />
     <Setter Property="Background" Value="{AppThemeBinding Dark={x:StaticResource AndoidDark}, Light=White}" />
 </Style>

https://reccloud.com/u/4nj3a0j

Platform affected: Windows

.Net 8

Maui 8.0.1

Visual Studio 2022 17.11

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author

Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,166 Reputation points Microsoft External Staff
2024-10-14T01:46:33.6766667+00:00

Hello,

For customizing the platform-specific UI, you can use the OnPlatfrom feature to quickly accomplish this requirement.

For the Margin property, since you have to fill in multiple values at once, you need to include it in single quotes for it to take effect.

Please refer to the following documentation and examples:

<Setter Property="Margin" Value="{OnPlatform WinUI='0', Default='66,100,0,0' }" />

Best Regards,

Alec Liu.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.