小编kle*_*neg的帖子

如何使ItemsControl拉伸以填充所有可用空间?

我有一个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)

wpf xaml resize itemscontrol

3
推荐指数
3
解决办法
5348
查看次数

覆盖不同命名空间C#中的方法

我在不同的项目中有两个班.

第一个命名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)

谢谢您的帮助.

c# polymorphism inheritance overriding namespaces

2
推荐指数
1
解决办法
2494
查看次数

如何获取从公共类继承的两组对象的并集

假设我有两个类,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# linq union

2
推荐指数
1
解决办法
60
查看次数