我有一个ItemsControl,其ItemsSource绑定到项目列表。每个项目的大小都尽可能小,我需要的是控件,控件中的项目可以拉伸以适合所有可用空间。
我尝试在控件及其项目上(使用样式)将VerticalAlignment设置为Stretch。我还尝试将ItemsControl包装在DockPanel中,并将ItemsControl停靠在底部。我如何让ItemsControl动态调整大小?
某些(但不是全部)项目的可见性也设置为“已折叠”(通过相同样式)。这将是完成此工作的一个因素吗?
<DockPanel HorizontalAlignment="Stretch">
<ItemsControl DockPanel.Dock="Bottom"
ItemsSource="{Binding Owner.LoadPointCharts}"
HorizontalAlignment="Stretch"
x:Name="ItemsControl">
<ItemsControl.ItemContainerStyle><!--Height="{Binding Path=Height, RelativeSource={RelativeSource AncestorType={x:Type DockPanel}}}"-->
<Style TargetType="ContentPresenter">
<Setter Property="VerticalAlignment"
Value="Stretch" />
<Setter Property="Visibility">
<Setter.Value>
<MultiBinding Converter="{StaticResource CompareIndexToVisibilityConverter}">
<Binding Path="Index" />
<Binding Path="SelectedIndex" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style >
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</DockPanel>
Run Code Online (Sandbox Code Playgroud) 我在不同的项目中有两个班.
第一个命名GeneralConcept
在命名空间,I.am.here
并有一个protected virtual
名为的方法DoSomething
.
第二个是命名的SpecificInstanceOfConcept
,位于命名空间I.am.in.a.different.place
并继承自GeneralConcept
.
我试图覆盖该方法.具有相同的名称,相同的输入,相同的类型,并从实现该方法的类继承.但是,
我一直在说错误
没有合适的方法来覆盖
它的设置方式如下所示,
namespace I.am.here
{
public class GeneralConcept
{
//stuff
protected virtual MyType DoSomething(Inputs input)
{
//more stuff
}
}
}
namespace I.am.in.a.different.place
{
public class SpecificInstanceOfConcept : I.am.here.GeneralConcept
{
//yet more stuff
protected override MyType DoSomething(Inputs input)
{
//even more stuff
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助.
假设我有两个类,Plane和Car,它们都继承自Vehicle
public class Vehicle
{
}
public class Car : Vehicle
{
}
public class Plane : Vehicle
{
}
Run Code Online (Sandbox Code Playgroud)
如何获取飞机列表和汽车列表并将它们合并为一个车辆列表?我尝试了下面这个,但是在汽车上有一个错误,说最好的重载必须采用IEnumerable类型的接收器
List<Vehicle> vehicles = cars.Union(planes);
Run Code Online (Sandbox Code Playgroud)
有没有比使用两个.Select循环将所有对象强制转换为Vehicle更简单的方法?
c# ×2
inheritance ×1
itemscontrol ×1
linq ×1
namespaces ×1
overriding ×1
polymorphism ×1
resize ×1
union ×1
wpf ×1
xaml ×1