【问题标题】:Add shapes in Listview - xamarin form在 Listview 中添加形状 - xamarin 表单
【发布时间】:2022-01-19 06:25:37
【问题描述】:

我正在使用具有 android 和 ios 项目的 Xamarin.Form,我想在列表视图中创建添加形状。

我找的是一样的,可以用路径类但是不知道怎么用。

请将您的解决方案发给我

谢谢

【问题讨论】:

    标签: c# xamarin xamarin.forms mobile drawing


    【解决方案1】:

    有路径类你可以使用它。 路径类有一个数据属性。例如

    <Path Data="M 10,100 L 100,100 100,50Z"
      Stroke="Black"
      Aspect="Uniform"
      HorizontalOptions="Start" />
    

    数据字符串以移动命令开头,用 M 表示,它为路径建立了一个绝对起点。 L 是 line 命令,它创建从起点到指定终点的直线。 Z 是关闭命令,它创建一条连接当前点和起点的线。

    请查看下面给出的链接,路径已添加到列表视图中: https://xamarinuidesigns.blogspot.com/2021/12/listview-ui-design-2.html

    【讨论】:

      【解决方案2】:

      您可以使用Composite geometries。

       <Path StrokeThickness="2" Fill="Orange">
                                      <Path.Data>
                                          <GeometryGroup FillRule="Nonzero">
                                              <RectangleGeometry Rect="0,0,50,50" />
                                              <EllipseGeometry RadiusX="25"
                               RadiusY="25"
                               Center="50,25" />
                                          </GeometryGroup>
                                      </Path.Data>
                                  </Path>
      

      在列表视图中的使用:

         <ListView ItemsSource="{Binding list}" RowHeight="60">
                  <ListView.ItemTemplate>
                      <DataTemplate>
                          <ViewCell>
                              <StackLayout Orientation="Horizontal">
                                  <Path StrokeThickness="2" Fill="Orange">
                                      <Path.Data>
                                          <GeometryGroup FillRule="Nonzero">
                                              <RectangleGeometry Rect="0,0,50,50" />
                                              <EllipseGeometry RadiusX="25"
                               RadiusY="25"
                               Center="50,25" />
                                          </GeometryGroup>
                                      </Path.Data>
                                  </Path>
                                  <Label Text="{Binding Name}"></Label>
                              </StackLayout>
                          </ViewCell>
                      </DataTemplate>
                  </ListView.ItemTemplate>
              </ListView>
      

      有关复合几何的更多详细信息,请查看以下链接。 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/geometries#composite-geometries

      【讨论】:

        【解决方案3】:
        <Path Data="M 10,100 L 100,100 100,50Z"
          Stroke="Black"
          Aspect="Uniform"
          HorizontalOptions="Start" />
        

        https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/path

        请查看此链接,如果您有任何问题可以问我?

        【讨论】:

        • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。
        猜你喜欢
        • 2018-06-26
        • 1970-01-01
        • 2018-03-11
        • 2018-03-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-10
        • 2018-03-08
        相关资源
        最近更新 更多