Сетка внутри Сетка в XAML

Для тех, кому нужны такие объекты, как {foo: 'bar}, я разделяю мою отредактированную версию ответа @ KevinBurke. Я добавил JSON.stringify и JSON.parse, вот и все.

cookie = {

    set: function (name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else
            var expires = "";
        document.cookie = name + "=" + JSON.stringify(value) + expires + "; path=/";
    },

    get : function(name){
        var nameEQ = name + "=",
            ca = document.cookie.split(';');

        for(var i=0;i < ca.length;i++) {
          var c = ca[i];
          while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) 
              return  JSON.parse(c.substring(nameEQ.length,c.length));
        }

        return null;
    }

}

Итак, теперь вы можете делать такие вещи:

cookie.set('cookie_key', {foo: 'bar'}, 30);

cookie.get('cookie_key'); // {foo: 'bar'}

cookie.set('cookie_key', 'baz', 30);

cookie.get('cookie_key'); // 'baz'
13
задан Anirudha Gupta 26 June 2019 в 04:23
поделиться

3 ответа

На основе вашего кода, только немного исправил:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition  />
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
    </Grid>
</Grid>

Обратите внимание, что ColumnDefinition не имеют Height - они имеют Width. Вам также нужно определить ColumnDefinitions и RowDefinitions отдельно - у вас они смешаны вместе в вашей внешней сетке. Я удалил RowDefinitions из внешней сетки, потому что, похоже, вы их не используете. Ваша внутренняя сетка имеет два столбца и четыре строки.

25
ответ дан 1 December 2019 в 19:39
поделиться

Phenevo, в этом году я много занимался дизайном XAML UI. Попробуйте это, вы можете легко перенести код в Window или UserControl. Я выделил цветом сетки и панели, чтобы вы могли подтвердить их расположение в реальном времени - удалите фоновые параметры, когда будете удовлетворены.

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="UatControlLibrary.sampleChilGrid"
    x:Name="UserControl"
    MinWidth="400"
    MinHeight="300"
    Width="auto"
    Height="auto">
    <Grid
        x:Name="LayoutRoot">
        <Grid
            x:Name="parentGrid"
            Width="auto"
            Height="auto"
            Background="Red">
            <Grid.ColumnDefinitions>
                <ColumnDefinition
                    Width="1*" />
                <ColumnDefinition
                    Width="1*" />
            </Grid.ColumnDefinitions>
            <Grid
                x:Name="chilGrid"
                Width="auto"
                Height="auto"
                Background="Black"
                Grid.Column="1"
                Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition
                        Width="1*" />
                    <ColumnDefinition
                        Width="1*" />
                </Grid.ColumnDefinitions>
                <StackPanel
                    x:Name="stkpnlLabels"
                    Background="White"
                    Grid.Column="0"
                    Grid.Row="0" />
                <StackPanel
                    x:Name="stkpnlTextboxes"
                    Background="Blue"
                    Grid.Column="1"
                    Grid.Row="0" />
            </Grid>
        </Grid>
    </Grid>
</UserControl>
1
ответ дан 1 December 2019 в 19:39
поделиться

Возможно, вы найдете это полезным. Попробуйте вставить это в страницу с помощью Kaxaml и поиграть с различными параметрами объектов во внешней сетке. Я считаю использование Kaxaml для создания прототипов и экспериментов с макетами XAML незаменимым.

<Grid>  
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto"/>
    <ColumnDefinition Width="Auto"/>
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
    <RowDefinition/>
    <RowDefinition/>
    <RowDefinition/>
  </Grid.RowDefinitions>

  <!-- 
     When I'm composing grids in XAML, I group things together by type, not by where
     they live in the grid.  This turns out to make a lot of maintenance tasks
     easier.

     Also, since Grid.Row and Grid.Column default to 0, a lot of people (and tools)
     omit them if that's their value.  Not me.  It lets me quickly check to make
     sure that content is where I think it is, just by looking at how it's organized
     in the XAML.
  -->

  <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Background="Lavender" Padding="10" HorizontalAlignment="Stretch">Here's the first row of the outer grid.</TextBlock>
  <TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Background="Lavender" Padding="10" HorizontalAlignment="Stretch">Here's the third row of the outer grid.</TextBlock>

  <TextBlock Grid.Row="1" Grid.Column="0" Background="AliceBlue" Padding="10">Here's the first column of the second row.</TextBlock>

  <Grid Grid.Row="1" Grid.Column="1">
    <Grid.ColumnDefinitions>
      <!--
         This part's pretty important.  Setting up the SharedSizeGroups for these
         two columns keeps the labels and text boxes neatly arranged irrespective of
         their length.
      -->
      <ColumnDefinition SharedSizeGroup="Label"/>
      <ColumnDefinition SharedSizeGroup="TextBox"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition/>
      <RowDefinition/>
      <RowDefinition/>
    </Grid.RowDefinitions>

    <Label Grid.Row="0" Grid.Column="0">First label</Label>
    <Label Grid.Row="1" Grid.Column="0">Second label</Label>
    <Label Grid.Row="2" Grid.Column="0">Third label, containing unusually long content</Label>

    <TextBox Grid.Row="0" Grid.Column="1">First text box, containing unusually long content</TextBox>
    <TextBox Grid.Row="1" Grid.Column="1">Second text box</TextBox>
    <TextBox Grid.Row="2" Grid.Column="1">Third text box</TextBox>

  </Grid>

</Grid>
8
ответ дан 1 December 2019 в 19:39
поделиться
Другие вопросы по тегам:

Похожие вопросы: