1. WPF 一行上3个控件 左右都是图片 中间是文字 如果文字过长 会覆盖右边的图片 该如何解决
你是要实现这2个iamge控件同时显示同一个图片吗,如果是的话就用数据绑定
2. WPF中什么控件能够既显示图片,又显示文字
其实不改模板就可以实现的呢。因为Button本身是一个ContentControl,所以里面可以塞任何控件的。demo如下: 文本内容
3. 用WPF编程,本来在canvas上显示图像了。如何在上面继续显示文字啊谢谢了
http://stackoverflow.com/questions/13374270/dynamic-data-display-wpf-need-to-add-text-to-canvas-c-sharp
4. (跪求)WPF下的RichTextBox控件下动态添加文字和图片
。。。灵活一点!!!在StackPanl内放image跟RichtextBox两个控件,分别存放图片跟文字不是一样能解决问题吗?
5. c# WPF panel 里面有个listview,listview里面有图片和文字,怎么能将这个listview在打印预览中显示出来
参考资料
http://stackoverflow.com/questions/2322064/how-can-i-proce-a-print-preview-of-a-flowdocument-in-a-wpf-application
6. WPF中哪种组件可以实现以下文字显示效果
WPF中没有直接的控件能够达到这个效果,要自己写控件。给你写了个自定义控件的例子,代码如下:
【代码1】自定义控件RowTextPresenter,提供隔行效果的控件。(示例代码,仅仅封装了FontSize和FontFamily属性,你可以仿造示例自行封装)
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows;
usingSystem.Windows.Controls;
usingSystem.Windows.Data;
usingSystem.Windows.Documents;
usingSystem.Windows.Input;
usingSystem.Windows.Media;
usingSystem.Windows.Media.Imaging;
usingSystem.Windows.Navigation;
usingSystem.Windows.Shapes;
namespaceWpfTextRow.Controls
{
publicclassRowTextPresenter:FrameworkElement
{
privateTextBlock_textPresenter=newTextBlock();
privateDrawingVisual_rowsPresenter=newDrawingVisual();
publicRowTextPresenter()
{
_textPresenter.TextWrapping=TextWrapping.Wrap;
this.AddVisualChild(_rowsPresenter);
this.AddVisualChild(_textPresenter);
}
{
get
{
return2;
}
}
(intindex)
{
if(index==0)return_rowsPresenter;
if(index==1)return_textPresenter;
();
}
protectedoverridevoidOnRender(DrawingContextdrawingContext)
{
base.OnRender(drawingContext);
DrawRows();
}
(SizeavailableSize)
{
_textPresenter.Measure(availableSize);
return_textPresenter.DesiredSize;
}
(SizefinalSize)
{
_textPresenter.Arrange(newRect(newPoint(0,0),finalSize));
returnfinalSize;
}
privatevoidDrawRows()
{
if(_textPresenter==null||_rowsPresenter==null)
return;
varwidth=_textPresenter.ActualWidth;
//通过反射的方式获取折行的行数
varlineCount=_textPresenter.ReflectGetProperty<int>("LineCount");
vardc=_rowsPresenter.RenderOpen();
if(lineCount>1)
{
varoffsetY=0.0;
varbaseValue=(this.AlternationMode==AlternationMode.Even)?1:0;
for(inti=0;i<lineCount;i++)
{
//通过反射的方式获取每一行的高度
varlineMetrics=_textPresenter.ReflectCall("GetLine",i);
varlineHeight=lineMetrics.ReflectGetProperty<double>("Height");
//判断奇偶行,绘制背景块
if(i%2==baseValue)
{
dc.DrawRectangle(this.AlternationBackground,null,newRect(0,offsetY,width,lineHeight));
}
offsetY+=lineHeight;
}
}
dc.Close();
}
#regionFontSize
=
TextElement.FontSizeProperty.AddOwner(typeof(RowTextPresenter),
newFrameworkPropertyMetadata((double)12.0));
publicdoubleFontSize
{
get{return(double)GetValue(FontSizeProperty);}
set{SetValue(FontSizeProperty,value);}
}
#endregion
#regionFontFamily
///<summary>
///FontFamilyDependencyProperty
///</summary>
=
TextElement.FontFamilyProperty.AddOwner(typeof(RowTextPresenter),
newFrameworkPropertyMetadata(null));
///<summary>
///.Thisdependencyproperty
///indicates....
///</summary>
publicFontFamilyFontFamily
{
get{return(FontFamily)GetValue(FontFamilyProperty);}
set{SetValue(FontFamilyProperty,value);}
}
#endregion
#regionText
=
DependencyProperty.Register("Text",typeof(string),typeof(RowTextPresenter),
newFrameworkPropertyMetadata(null,
.AffectsRender,
newPropertyChangedCallback(OnTextChanged)));
publicstringText
{
get{return(string)GetValue(TextProperty);}
set{SetValue(TextProperty,value);}
}
(DependencyObjectd,)
{
((RowTextPresenter)d).OnTextChanged(e);
}
()
{
_textPresenter.Text=(string)e.NewValue;
}
#endregion
#regionAlternationBackground
=
DependencyProperty.Register("AlternationBackground",typeof(Brush),typeof(RowTextPresenter),
newFrameworkPropertyMetadata(null,
.None,
newPropertyChangedCallback()));
{
get{return(Brush)GetValue(AlternationBackgroundProperty);}
set{SetValue(AlternationBackgroundProperty,value);}
}
privatestaticvoid(DependencyObjectd,)
{
((RowTextPresenter)d).(e);
}
protectedvirtualvoid()
{
this.DrawRows();
}
#endregion
#regionAlternationMode
=
DependencyProperty.Register("AlternationMode",typeof(AlternationMode),typeof(RowTextPresenter),
newFrameworkPropertyMetadata(AlternationMode.Even,
.AffectsRender));
{
get{return(AlternationMode)GetValue(AlternationModeProperty);}
set{SetValue(AlternationModeProperty,value);}
}
#endregion
}
///<summary>
///跳行模式
///</summary>
publicenumAlternationMode
{
///<summary>
///从偶数行开始
///</summary>
Even,
///<summary>
///从奇数行开始
///</summary>
Odd
}
}
【代码2】ReflectionService,提供反射功能的工具类
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Reflection;
namespaceWpfTextRow.Controls
{
{
=
BindingFlags.Public|
BindingFlags.NonPublic|
BindingFlags.Instance;
<T>(thisobjecttarget,stringpropertyName)
{
vartype=target.GetType();
varpropertyInfo=type.GetProperty(propertyName,ReflectionFlags);
return(T)propertyInfo.GetValue(target,null);
}
publicstaticobjectReflectCall(thisobjecttarget,stringmethodName,paramsobject[]args)
{
vartype=target.GetType();
varpropertyInfo=type.GetMethod(methodName,ReflectionFlags);
returnpropertyInfo.Invoke(target,args);
}
}
}
【代码3】使用的代码
<l:="LightGreen"
FontSize="14"
Text="BEIJING—AstudybyChina'-onrules,.Thestudy,meantforinternaldistribution,-equipmentmakers,suchasHuaweiTechnologiesCo.andZTECorp.,.subsidiesbyfundingresearch-and-developmentprojects,,saidtheperson,whodeclinedtobenamed."/>
【效果图片】