有没有可能将进度条嵌套到组合框中,或者反过来。我希望能够像在Windows资源管理器中那样,在组合框中键入内容,然后点击一个按钮,进度条就会显示事件的进度。
编辑:我需要Visual Basic.NET 3.5中的代码,谢谢。
发布于 2010-07-04 22:35:48
这是一种方法,基本上我所做的是:
首先是新的控制代码:
public class ProgressCombo : ComboBox
{
public static readonly DependencyProperty IsProgressVisibleProperty =
DependencyProperty.Register("IsProgressVisible", typeof(bool), typeof(ProgressCombo));
public bool IsProgressVisible
{
get { return (bool)GetValue(IsProgressVisibleProperty); }
set { SetValue(IsProgressVisibleProperty, value); }
}
public static readonly DependencyProperty ProgressValueProperty =
DependencyProperty.Register("ProgressValue", typeof(double), typeof(ProgressCombo));
public double ProgressValue
{
get { return (double)GetValue(ProgressValueProperty); }
set { SetValue(ProgressValueProperty, value); }
}
}还有一个我们将使用的值转换器:
public class FromPercentConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ((double)value) / 100;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}现在从http://msdn.microsoft.com/en-us/library/ms750638%28VS.90%29.aspx的MSDN (.net 3.5版本,而不是4)中获取组合框样例样式
将xmlns:l定义添加到您自己的程序集中
现在将<Style x:Key="{x:Type ComboBox}" TargetType="ComboBox">更改为<Style x:Key="{x:Type l:ProgressCombo}" TargetType="l:ProgressCombo">
将<ControlTemplate TargetType="l:ComboBox">更改为:
<ControlTemplate TargetType="l:ProgressCombo">
<ControlTemplate.Resources>
<BooleanToVisibilityConverter x:Key="Bool2Vis"/>
<l:FromPercentConverter x:Key="FromPercent"/>
</ControlTemplate.Resources>找到<ContentPresenter行并在其前面添加:
<Rectangle
Fill="LightGreen"
Margin="3,3,23,3"
Visibility="{TemplateBinding IsProgressVisible, Converter={StaticResource Bool2Vis}}">
<Rectangle.RenderTransform>
<ScaleTransform ScaleX="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ProgressValue, Converter={StaticResource FromPercent}}"/>
</Rectangle.RenderTransform>
</Rectangle>就是这样
发布于 2010-07-04 08:25:09
出于不同的原因,我也有类似的需求(我有一个在网络扫描后自动填充的组合)。看看这个问题和答案是否对你有帮助:WPF ComboBox - showing something different when no items are bound
https://stackoverflow.com/questions/3173254
复制相似问题