我正在开发 Windows Phone 8 应用程序,其中我有一个 Stackpanel,我想在其中放置 7 个矩形。无论屏幕大小如何,我都希望这些矩形的高度相同。我尝试设置Height="*"但它给出了错误。
<StackPanel>
<Rectangle Fill="Violet" Height="*"></Rectangle>
<Rectangle Fill="Indigo" Height="*"></Rectangle>
<Rectangle Fill="Blue" Height="*"></Rectangle>
<Rectangle Fill="Green" Height="*"></Rectangle>
<Rectangle Fill="Yellow" Height="*"></Rectangle>
<Rectangle Fill="Orange" Height="*"></Rectangle>
<Rectangle Fill="Red" Height="*"></Rectangle>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我吗?
我正在尝试获取 GridRow[0] 及其父级 (Stackpanel) 的值,然后减去 Stackpanel 值的 GridRow[0] 的值。我的最后一步是将结果分配给 GridRow[1]。
gridLengthVariable = othergridLengthVariable - doubleVariable;
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我无法进行从 Double 到 GridLength 的显式转换
gridLengthVariable.Value
Run Code Online (Sandbox Code Playgroud)
是一个只读属性,所以我不能在这里分配。
我需要一种将 double 转换为 gridLength 的方法,尽管如果这给我带来了相同的解决方案,我愿意对我的代码进行更深入的更改。
无法完成 XAML 更改。
编辑:
我将展示我正在尝试做的事情:
它是 XAML 创建的 gridRow 的动态更改。
gridProfile.RowDefinitions[1].Height =
stackPanelProfile.Height - gridProfile.RowDefinitions[0].Height;
Run Code Online (Sandbox Code Playgroud)
在这里我不能应用运算符“ - ”
谢谢。
我有对象我正在数据绑定到WPF中的ListBox.以下是最终结果的样子:
------------------------------- | Name | Opt1 | Value1 | | | Opt2 | Value2 | | | Opt3 | Value3 | | | Opt4 | Value4 | -------------------------------
基本上我有一个整体变量的DataTemplate,然后Opt/Value组合有它自己的DataTemplate.我正在尝试尽可能简单地显示值列表.
<Label Content="{Binding Path=Identifier.Name, Mode=OneWay}" />
<ListView Grid.Column="1" HorizontalAlignment="Stretch"
ItemsSource="{Binding Path=Values, Mode=OneWay}" />
Run Code Online (Sandbox Code Playgroud)
Value的绑定目前只有<Grid>2 <Label>,而ListView有很多我不看的功能,比如边框样式,选择等,当我真正想要的是能够使用List进行数据绑定时.
我试图将项目数据绑定到一个堆栈面板,但无法让它在XAML中工作.我想另一个解决方案是做我正在做的事情,并重写<Style>for ListView.有关正确方法的任何建议吗?
我可以在代码隐藏中设置stackpanel的边距,如下所示:
StackPanel sp2 = new StackPanel();
sp2.Margin = new System.Windows.Thickness(5);
Run Code Online (Sandbox Code Playgroud)
但是如何单独设置,这两个都不起作用:
伪代码:
sp2.Margin = new System.Windows.Thickness("5 0 0 0");
sp2.Margin.Left = new System.Windows.Thickness(5);
Run Code Online (Sandbox Code Playgroud) 我有与引用完全相同的问题(在这里采取,但没有回答):
我通过StackPanel.Childrens.Add()将控件添加到StackPanel.
但是我所看到的 - 我添加的所有控件都处于相同的位置并相互重叠.它们不在StackPanel内部布局.
甚至StackPanel.UpdateLayout()也没有给我带来什么.
我对我来说是想添加Canvases(是的,我确实需要它们)StackPanel.有任何想法吗?
有没有办法让 StackPanel 中第一个控件的阴影出现在第二个控件的顶部?我有这个问题,看图!
替代文字 http://img2.imageshack.us/img2/7073/issuef.png
代码示例:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Grid>
<StackPanel>
<Border Height="100" Width="100" Background="Red">
<Border.BitmapEffect>
<DropShadowBitmapEffect Color="Black" Direction="270" ShadowDepth="3" Opacity="1" Softness="2" />
</Border.BitmapEffect>
</Border>
<Border Height="100" Width="100" Background="blue">
</Border>
</StackPanel>
</Grid>
</Page>
Run Code Online (Sandbox Code Playgroud) 
我有一个WrapPanel(绿色背景)ListBox(灰色背景).
我试图动态添加StackPanel多次(通过点击给定图像下面的按钮)WrapPanel.
该StackPanel包含Button哪些内容具有"X".StackPanel单击此按钮时,我想删除单个对象(橙色背景).
怎么能解决?
我有一个字符串列表.例如,"abc","pqr","xyz"按此顺序.StackPanel是绑定到此列表的数据.我想在StackPanel中垂直显示列表,但从上到下依次反向显示
"xyz"
"pqr"
"abc"
Run Code Online (Sandbox Code Playgroud)
有没有办法在xaml中执行此操作或者我是否需要重新排序列表?
我有以下问题.我正在使用Items控件,我不明白为什么我的结果是在几行而不是在一行上.这是我的代码:
<StackPanel Orientation="Horizontal" Margin="10,10,10,10">
<ItemsControl ItemsSource="{Binding Countries}" >
<ItemsControl.ItemTemplate>
<DataTemplate x:Name="TabCountries" >
<StackPanel Orientation="Horizontal">
<TextBlock Name="Country" Text="{Binding nom}" Style="{StaticResource whiteFontColor}" VerticalAlignment="Center" Margin="0,0,5,0"/>
<CheckBox Margin="0,0,5,0" Name="isCountryAllowed" IsChecked="{Binding isAllowed}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
结果是这样的:
FR
BE
AN
Run Code Online (Sandbox Code Playgroud)
而不是那样:
FR BE AN ...
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?
我有一个Windows 8 C# - xaml应用程序.我有一个堆叠面板,里面有6个堆叠面板.每个堆叠面板有7个按钮.所以整个事情是6x7按钮形成一个日历.主堆栈面板放置在网格中.
现在按钮没有内容集.在后面的代码中,这些按钮的日期设置为内容.
我的问题是,对于不同的分辨率,网格扩展了堆栈面板,但内部的按钮更小,以适应内容.我想按钮扩展,以填满整个堆栈面板.主网格,主堆栈面板,子堆栈面板和按钮的高度和宽度设置为自动..
我一直试图实现这一目标.但是徒劳!有什么建议?
编辑:
有一个主网格,它包含BackButtonGrid,CalendarGrid,NotesGrid和StatusGrid.
CalendarGrid有一个
2个文本框显示一些值.
<Grid Style="{StaticResource LayoutRootStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- Back button and page title -->
<Grid x:Name="BackButtonGrid" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
<TextBlock x:Name="pageTitle" Grid.Column="1" Text="Calendar" Style="{StaticResource PageHeaderTextStyle}"/>
</Grid>
<Grid x:Name="CalendarGrid" Width="Auto" Height="Auto" Grid.Column="1" Grid.Row="1" VerticalAlignment="Stretch">
<Grid.Background>
<ImageBrush …Run Code Online (Sandbox Code Playgroud)stackpanel ×10
wpf ×7
xaml ×5
c# ×4
layout ×2
.net ×1
button ×1
canvas ×1
code-behind ×1
itemscontrol ×1
listbox ×1
margin ×1
shadow ×1
windows-8 ×1
wrappanel ×1