积极答复者
ListBox 去除默认边框问题,beta 2中显示正常,RTW中显示不正常

问题
-
beta 2的时候显示正常,现在升级到RTW显示不正常,不知道RTW有啥变化了?
<ListBox x:Name="listBox1" Canvas.Left="250" Canvas.Top="8" Style="{StaticResource Style1}" >
App.xaml文件中:
<Application.Resources>
<Style x:Key="Style1" TargetType="ListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<Grid><ScrollViewer x:Name="ScrollViewer" VerticalScrollBarVisibility="Auto" BorderThickness="0" HorizontalScrollBarVisibility="Auto">
<ItemsPresenter />
</ScrollViewer>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
</Application>2008年11月4日 3:31
答案
-
不知道我理解的对不对.我做了个Demo,是没有边框的.要是你能在我没删除Demo前加我我可以把测试工程发给你.
QQ 14682233 45166608
UserControl(你上面提到过加一个UserControl就会有边框,所以我加了一个测试的UserControl)
<UserControl
x:Class="SilverlightApplication1.SilverlightControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Grid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
>
<TextBlock
Text="Test"
/>
</Grid>
</UserControl>
App.xaml
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SilverlightApplication1.App"
>
<Application.Resources>
<Style
x:Key="ListBox"
TargetType="ListBox"
>
<Setter
Property="Template"
>
<Setter.Value>
<ControlTemplate
TargetType="ListBox"
>
<Grid>
<ScrollViewer
x:Name="ScrollViewer"
Padding="{TemplateBinding Padding}"
BorderThickness="0"
>
<ItemsPresenter />
</ScrollViewer>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style
x:Key="ListBoxItem"
TargetType="ListBoxItem"
xmlns:vsm="clr-namespaceystem.Windows;assembly=System.Windows"
>
<Setter
Property="Background"
Value="#FFFFFFFF"
/>
<Setter
Property="Template"
>
<Setter.Value>
<ControlTemplate
TargetType="ListBoxItem"
>
<Grid
Background="{TemplateBinding Background}"
>
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Margin="5"
/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources></Application>
CStudent类
public class CStudent
{
public string ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}Page.xaml
<UserControl
x:Class="SilverlightApplication1.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlnsyc="clr-namespace
ilverlightApplication1;assembly=SilverlightApplication1"
>
<Grid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
>
<ListBox
x:Name="listboxStudent"
Width="300"
Height="200"
Style="{StaticResource ListBox}"
ItemContainerStyle="{StaticResource ListBoxItem}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel
Orientation="Horizontal"
>
<sycilverlightControl1></syc
ilverlightControl1>
<TextBlock
Margin="10,0,0,0"
Text="{Binding Name}"
/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</UserControl>using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;namespace SilverlightApplication1
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
InitObject();
}private void InitObject()
{
lstStudent = new List<CStudent>();lstStudent.Add(new CStudent() { ID = "1", Name = "Name1", Age = 18 });
lstStudent.Add(new CStudent() { ID = "2", Name = "Name2", Age = 18 });
lstStudent.Add(new CStudent() { ID = "3", Name = "Name3", Age = 18 });
lstStudent.Add(new CStudent() { ID = "4", Name = "Name4", Age = 18 });
lstStudent.Add(new CStudent() { ID = "5", Name = "Name5", Age = 18 });
lstStudent.Add(new CStudent() { ID = "6", Name = "Name6", Age = 18 });
lstStudent.Add(new CStudent() { ID = "7", Name = "Name7", Age = 18 });listboxStudent.ItemsSource = lstStudent;
}private System.Collections.Generic.List<CStudent> lstStudent;
}
}2008年11月11日 3:26
全部回复
-
给你写了个Demo把所有的框都去掉了.
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SilverlightApplication1.App"
>
<Application.Resources>
<Style
x:Key="ListBox"
TargetType="ListBox"
>
<Setter
Property="Template"
>
<Setter.Value>
<ControlTemplate
TargetType="ListBox"
>
<Grid>
<ScrollViewer
x:Name="ScrollViewer"
Padding="{TemplateBinding Padding}"
BorderThickness="0"
>
<ItemsPresenter />
</ScrollViewer>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
</Application>2008年11月4日 6:20 -
我的问题依然存在,不知道怎么解决!
<UserControl x:Class="Test.ListBox"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Canvas x:Name="LayoutRoot" Background="White">
<ListBox x:Name="ListBox1" BorderThickness="0" Background="Wheat" Width="200" Height="100" Canvas.Top="0">
<ListBoxItem Content="item1" />
<ListBoxItem Content="item2" />
<ListBoxItem Content="item3" />
</ListBox><ListBox x:Name="ListBox2" BorderThickness="0" Width="200" Background="Black" Canvas.Top="120">
</ListBox>
</Canvas>
</UserControl>后台代码:
for (int i = 0; i < 6; i++)
{
ListBoxItem1 item = new ListBoxItem1(); //ListBoxItem1 是UseControl,XAML如下ListBox2.Items.Add(item);
}
UserControl的XAML
<UserControl x:Class="Test.ListBoxItem1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="180" Height="25">
<Canvas x:Name="LayoutRoot" Background="White">
<TextBlock Text="ListBoxItem1" FontSize="16" Canvas.Left="30"></TextBlock>
</Canvas>
</UserControl>效果:
2008年11月7日 9:09 -
不知道我理解的对不对.我做了个Demo,是没有边框的.要是你能在我没删除Demo前加我我可以把测试工程发给你.
QQ 14682233 45166608
UserControl(你上面提到过加一个UserControl就会有边框,所以我加了一个测试的UserControl)
<UserControl
x:Class="SilverlightApplication1.SilverlightControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Grid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
>
<TextBlock
Text="Test"
/>
</Grid>
</UserControl>
App.xaml
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SilverlightApplication1.App"
>
<Application.Resources>
<Style
x:Key="ListBox"
TargetType="ListBox"
>
<Setter
Property="Template"
>
<Setter.Value>
<ControlTemplate
TargetType="ListBox"
>
<Grid>
<ScrollViewer
x:Name="ScrollViewer"
Padding="{TemplateBinding Padding}"
BorderThickness="0"
>
<ItemsPresenter />
</ScrollViewer>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style
x:Key="ListBoxItem"
TargetType="ListBoxItem"
xmlns:vsm="clr-namespaceystem.Windows;assembly=System.Windows"
>
<Setter
Property="Background"
Value="#FFFFFFFF"
/>
<Setter
Property="Template"
>
<Setter.Value>
<ControlTemplate
TargetType="ListBoxItem"
>
<Grid
Background="{TemplateBinding Background}"
>
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Margin="5"
/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources></Application>
CStudent类
public class CStudent
{
public string ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}Page.xaml
<UserControl
x:Class="SilverlightApplication1.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlnsyc="clr-namespace
ilverlightApplication1;assembly=SilverlightApplication1"
>
<Grid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
>
<ListBox
x:Name="listboxStudent"
Width="300"
Height="200"
Style="{StaticResource ListBox}"
ItemContainerStyle="{StaticResource ListBoxItem}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel
Orientation="Horizontal"
>
<sycilverlightControl1></syc
ilverlightControl1>
<TextBlock
Margin="10,0,0,0"
Text="{Binding Name}"
/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</UserControl>using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;namespace SilverlightApplication1
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
InitObject();
}private void InitObject()
{
lstStudent = new List<CStudent>();lstStudent.Add(new CStudent() { ID = "1", Name = "Name1", Age = 18 });
lstStudent.Add(new CStudent() { ID = "2", Name = "Name2", Age = 18 });
lstStudent.Add(new CStudent() { ID = "3", Name = "Name3", Age = 18 });
lstStudent.Add(new CStudent() { ID = "4", Name = "Name4", Age = 18 });
lstStudent.Add(new CStudent() { ID = "5", Name = "Name5", Age = 18 });
lstStudent.Add(new CStudent() { ID = "6", Name = "Name6", Age = 18 });
lstStudent.Add(new CStudent() { ID = "7", Name = "Name7", Age = 18 });listboxStudent.ItemsSource = lstStudent;
}private System.Collections.Generic.List<CStudent> lstStudent;
}
}2008年11月11日 3:26