我创建了一个用户控件类库,并在其中使用了ResourceDictionary文件.现在,我想在WPF应用程序中使用我的usercontrol,但我必须在我的项目中再次添加ResourceDictionary文件!如果我不添加它,它会带来ResourceDictionary文件,并在MergeDictionaries块上显示错误!我错过了什么!?
资源字典是:
<ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type s:MoveThumb}">
<Rectangle Fill="Transparent" Cursor="Hand"/>
</ControlTemplate>
<Style x:Key="ItemStyle" TargetType="ContentControl">
<Setter Property="Width" Value="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Canvas}},Path=ActualWidth}"/>
<Setter Property="MinHeight" Value="60"/>
<Setter Property="Height" Value="60"/>
<Setter Property="Content" Value="MyTextBox"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<s:MoveThumb Template="{DynamicResource MoveThumbTemplate}"/>
<ContentPresenter Name="MainControl" Content="{TemplateBinding ContentControl.Content}"
Margin="5,0,10,0"/>
<Grid Opacity="0" Margin="-3">
<s:ResizeThumb Height="3" Cursor="SizeNS" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
<s:ResizeThumb Height="3" Cursor="SizeNS" VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
添加到用户控件:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/MoveResizeThumb.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud) 我ObservableCollection在ViewModel中有一个静态MarketList,它以Table下列方式绑定:
<FlowDocumentScrollViewer Height="216" VerticalAlignment="Top" Margin="-7,2,7,0" >
<FlowDocument>
<Table CellSpacing="0" Name="MBPTable" >
<Table.DataContext>
<MultiBinding UpdateSourceTrigger="Explicit" Mode="TwoWay" Converter="{StaticResource indexerConverter}">
<Binding Path="MarketList" UpdateSourceTrigger="PropertyChanged" NotifyOnSourceUpdated="True" Mode="TwoWay" BindsDirectlyToSource="True" />
<Binding Path="MBPindex" Mode="TwoWay" />
</MultiBinding>
</Table.DataContext>
<Table.Resources>
<local:IndexerConverter x:Key="indexerConverter"></local:IndexerConverter>
</Table.Resources>
Run Code Online (Sandbox Code Playgroud)
Table包含ListView哪个绑定到MarketList的Property.
<ListView Name="MarketByPriceList" Width="300" ItemsSource="{Binding MarketByPriceList, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" AlternationCount="2" Margin="0,15,0,0" >
<ListView.View>
<GridView>
<GridViewColumn Header="Orders" Width="48" DisplayMemberBinding="{Binding MBP_NoofBuy_Orders, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" ></GridViewColumn>
<GridViewColumn Header="Bid Qty" Width="48" DisplayMemberBinding="{Binding MBPBID_Qty, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" ></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)
这是转换器方法
public object Convert(object[] values, Type …Run Code Online (Sandbox Code Playgroud) 我有一个由滑块Grid缩放/缩放ScaleTransform的。在运行时,许多UIElement被添加到此Grid。
我想显示一些工具提示,但没有扩展!我应该怎么做?
例如:Grid具有scaleX和scaleY 2,因此我设置了新的ScaleTransform(0.5,0.5),但没有帮助。似乎最相似的值是0.740。为什么?甚至Grid的LayoutTransform.Inverse都将缩放比例值设置为0.5。
XAML:
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Height="Auto" Width="Auto" Name="graphScrollViewer" ScrollChanged="graphScrollViewer_ScrollChanged">
<Grid Margin="0,0,0,0" Name="graphGrid" Width="Auto" Height="Auto" ScrollViewer.IsDeferredScrollingEnabled="True" MouseLeftButtonDown="graphGrid_MouseLeftButtonDown" MouseLeftButtonUp="graphGrid_MouseLeftButtonUp" MouseMove="graphGrid_MouseMove">
<Grid.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=sldZoom, Path=Value}" ScaleY="{Binding ElementName=sldZoom, Path=Value}" />
</Grid.LayoutTransform>
</Grid>
</ScrollViewer>
<Slider Minimum="0.1" Maximum="20" Value="1" x:Name="sldZoom" Panel.ZIndex="10" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,20,20" Height="23" Width="100" ValueChanged="sldZoom_ValueChanged"/>
Run Code Online (Sandbox Code Playgroud)
后台代码:(将Rectangle方法(MouseEnter事件)动态添加到网格)
private void rect_MouseEnter(object sender, MouseEventArgs e)
{
RectToolTip = new TextBlock();
RectToolTip.HorizontalAlignment = HorizontalAlignment.Left;
RectToolTip.VerticalAlignment = VerticalAlignment.Top;
RectToolTip.TextAlignment = TextAlignment.Center;
RectToolTip.Height = this.HeaderTwoHeight …Run Code Online (Sandbox Code Playgroud)