在a Slider中插入Grid会扩展它以填充可用空间,但我不希望使用网格,原因如下:
我有一个TextBlock和Slider在UserControl,滑块装有弹簧,做慢跑/穿梭; 必须显示当前值,因为用户不能依赖中性光标的位置,所以文本块.实现**Orientation**这个自定义滑块的属性需要旋转两个组件,并调整它们的相对位置(左/右或上/下),这对于网格来说并不容易(除非我错过了明显的东西)用一个StackPanel.
回应Aviad的评论
Aviad,谢谢,我为痛苦道歉;-)问题出现在标题中:当滑块位于StackPanel内时,如何扩展Slider以填充可用空间?
这个用户控件:
<UserControl x:Class="XXX.Preview.SelectionView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="auto" Width="auto">
<GroupBox Header="Selected">
<StackPanel Orientation="Horizontal">
<TextBlock/>
<Slider/>
</StackPanel>
</GroupBox>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
即使在具有"*"宽度的行中,也不会在包含在网格中时展开.滑块根本没有长度.
一个解决方案是在下面的代码中用网格替换堆栈面板,但我不想使用网格,因为我需要使用堆栈面板的Orientation属性来显示封闭用户控件时垂直堆叠的控件在方向"垂直"中设置.
当我写这样的东西时:
<Style x:Key="panelS">
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="DockPanel.Dock" Value="Top" />
</Style>
Run Code Online (Sandbox Code Playgroud)
我收到错误消息:无法解析样式属性'Orientation'.验证拥有类型是Style的TargetType,还是使用Class.Property语法指定Property.
当然我有一个Dock面板,其中有许多Stackpanels,所以我想将Stackpanel的属性移动到样式.但是有这个错误,我不太明白这是什么意思,什么是解决方法(..我不想在每个Stackpanel上分配Orientation).
我正在开发windows phone 7应用程序.我是窗口手机7应用程序的新手.我的应用程序中有以下列表框控件
<ListBox Margin="0,355,70,205" Name="WeekSummaryListBox" DataContext="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Amount}" Foreground="Orange"></TextBlock>
<TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Currency}" Foreground="Orange"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Template>
<ControlTemplate>
<ScrollViewer HorizontalScrollBarVisibility="Visible">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ListBox.Template>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
在上面的列表框中,控件项目是垂直显示的.我想在列表框控件中显示项目.所以我使用以下代码.
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
Run Code Online (Sandbox Code Playgroud)
但是当我将两个文本块放在stackpanel中时,它会出错.为此,我使用以下代码
<StackPanel Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Amount}" Foreground="Orange"></TextBlock>
<TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Currency}" Foreground="Orange"></TextBlock>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
我正在尝试以下代码.在下面的代码中我收到错误
<ListBox Margin="0,355,70,205" Name="WeekSummaryListBox" DataContext="{Binding}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Amount}" Foreground="Orange"></TextBlock>
<TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Currency}" Foreground="Orange"></TextBlock> …Run Code Online (Sandbox Code Playgroud) 我试图存储我在隔离存储中创建的对象列表,并能够通过自动为它们生成标题在列表中显示它们.到目前为止,代码仍然有效,但是一旦我对应用程序进行了逻辑删除并启动它,除了对象列表之外,我的所有数据都会被保存.我认为我的问题可能在于我首先如何初始化列表,或者可能是我如何显示名称.任何帮助表示赞赏.
这段代码在我的App.xaml.cs中:
public partial class App : Application
{
public List<my_type> testList = new List<my_type>();
void loadvalues()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
List<my_Type> L;
if (settings.TryGetValue<List<DrinkSesh>>("Storage", out L))
{ testList = L; }
}
void savevalues()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings["Storage"] = testList;
settings.Save();
}
}
Run Code Online (Sandbox Code Playgroud)
此代码在我的mainPage上将项添加到列表中:
(Application.Current as App).testList.Add(new my_type());
Run Code Online (Sandbox Code Playgroud)
这段代码是在不同的页面上将标题实现到屏幕上:
public different_class()
{
{
InitializeComponent();
for (i = 0; i < (Application.Current as App).testList.Count; i++)
{
CreateATextBlock((Application.Current as App).testList[i].Title_ToString(), i);
}
}
private void CreateATextBlock(String title,int num) …Run Code Online (Sandbox Code Playgroud) 我有一个ObservableCollection按钮:
public partial class MainWindow : Window
{
public ObservableCollection<Button> myBtCollection { get; set; }
public MainWindow()
{
InitializeComponent();
myBtCollection = new ObservableCollection<Button>();
Button bot1 = new Button { Width = 200, Height = 25, Content = "Boton 1" };
Button bot2 = new Button { Width = 150, Height = 50, Content = "Boton 2" };
Button bot3 = new Button { Width = 100, Height = 100, Content = "Boton 3" };
myBtCollection.Add(bot1);
myBtCollection.Add(bot2);
myBtCollection.Add(bot3);
myBtCollection.Add(bot1);
myBtCollection.Add(bot3);
myBtCollection.Add(bot2); …Run Code Online (Sandbox Code Playgroud) 我正试图在c#中设置TreeViewItem- >的属性,StackPanel就像这个问题一样.它似乎很有意义,直到我到达我尝试编辑Background我的部分Border.它们中Borders有Background物体,但对于我的生命,我无法设置颜色或任何东西.它似乎是不一致的,因为我可以通过简单地说,添加Content到a .LabelContent = "Title"
无论如何,这是我的代码:
public static TreeViewItem childNode = new TreeViewItem() //Child Node
{
Header = new StackPanel
{
Orientation = Orientation.Horizontal,
Children =
{
new Border {
Width = 12,
Height = 14,
Background = ? //How do I set the background?
},
new Label {
Content = "Child1"
}
}
}
};
Run Code Online (Sandbox Code Playgroud)
PS - 我在尝试添加时遇到同样的问题 BorderBrush
谢谢!
在stackpanel中,我在运行时从代码中添加一些标签:我想让stackpanel可滚动.在xaml文件中我有:
<ScrollViewer HorizontalAlignment="Left" Height="299" Margin="592,120,0,0" VerticalAlignment="Top" Width="188" VerticalScrollBarVisibility="Auto">
<StackPanel x:Name="stackPanelVistaProfiloTessera" Height="292" Width="170"/>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
在后面的代码我添加一些标签到stackpanel:
for(.....)
{
stackPanelVistaProfiloTessera.Children.Add(new Label {....});
}
Run Code Online (Sandbox Code Playgroud)
为什么stackpanel不可滚动?我该如何解决这个问题?
谢谢
我想在datagrid长度超过 时滚动stackpanel,所以我尝试了这个:
<StackPanel Orientation="Horizontal">
<ScrollViewer VerticalScrollBarVisibility="Auto" CanContentScroll="True">
<DataGrid Name="dgConfig" VerticalAlignment="Stretch" AutoGenerateColumns="False">
<DataGrid.Columns>
...
</DataGrid.Columns>
</DataGrid>
</ScrollViewer>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
但这不起作用,我在此网络上搜索并未能找到任何可用的解决方案。那么我应该如何解决这个问题?谢谢!
我有一个wpf-mvvm应用程序.
我已经完成了......
<Combo box>
item 1
item 2
</Combo box>
<stack pnel>
<user control 1 />
<user control 1 />
</stack pnel>
Run Code Online (Sandbox Code Playgroud)
如果用户从组合中选择"项目1",我需要显示"用户控件1"如果用户从组合中选择"项目2",我需要显示"用户控件2"
在viewmodel中...我有一个这两个组合框项目的IList.
在这里隐藏/展示物品的最佳方法是什么?