locked
Enabling/Disabling hyperlink on a datagrid in wpf RRS feed

  • Question

  • I'm newbie to this wpf. I've the following WPF xaml code in my application. Right now, the numbers in colum on the the grid, show up as plain text with mouse double-click enabled on each of the numbers. I need to able to make each of these numbers as Hyperlink column and enable/disable them programmatically based on a flag...say EnableHyperlink. How do I achieve this please?

    I know how to create a simple hyperlink column in wpf...but I'm not able to do that in the following code.

    Thanks.

    MyScreen.xaml

    <UserControl x:Class="MyProject.MyModules.MyViews.MyDashboard"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:local="clr-namespace:MyProject.MyModules.MyViews"
                 xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol"
                 xmlns:widgets="clr-namespace:MyProject.MyModules.MyUserControls.MyWidgets"
                 xmlns:controls="clr-namespace:MyProject.MyModules.MyUserControls"
                 xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
                 xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
                 xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
                 xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking" 
                 xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
                 xmlns:uc="clr-namespace:MyProject.MyModules.MyUserControls"
                 xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
                 xmlns:myControls="clr-namespace:MyProject.MyControls;assembly=MyUIControls"
                 mc:Ignorable="d" 
                 d:DesignHeight="700" d:DesignWidth="1500">
    
    <dxlc:FlowLayoutControl Background="{x:Null}" Name="tileLayoutControl1" HorizontalAlignment="Left" 
                                    ItemSpace="10" LayerSpace="10" Padding="5,5,5,5" Margin="0,0,0,0" RenderTransformOrigin="0.501,0.559" Height="1000" Width="1600" VerticalAlignment="Top" ScrollBars="Auto">
                    <dxlc:Tile Name="tile1" Width="650" Height="310" Focusable="False" Background="Transparent" >
                        <myControls:TileContentHolder Heading="My title">
                            <dx:LoadingDecorator Style="{StaticResource ResourceKey=DxLoadingDecoratorStyle}" Tag="{Binding IsLoading}"  >
                                <Grid Margin="0">
                                    <controls:MyCustomColumnsFlatGrid  x:Name="myGrid"  ItemDoubleClick="myGrid_ItemDoubleClick"
                                                                 ItemsSource="{Binding mySummary}" >
                                    </controls:MyCustomColumnsFlatGrid>
                                </Grid>
                            </dx:LoadingDecorator>
                        </myControls:TileContentHolder>
                    </dxlc:Tile>
    </dxlc:FlowLayoutControl>
    </UserControl>

    MyCustomColumnsFlatGrid.xaml:

    <UserControl x:Class="MyProject.MyModules.MyUserControls.MyCustomColumnsFlatGrid"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
                 xmlns:controls="clr-namespace:MyProject.MyModules.MyUserControls"
                 xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
                 xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
                 xmlns:dxi="http://schemas.devexpress.com/winfx/2008/xaml/core/internal"
                 xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
                 >
        <UserControl.Resources>
            <Style TargetType="{x:Type dxg:DataPresenter}" x:Key="NoDataStyle" >
                <Setter Property="FontSize" Value="20" />
            </Style>
            <dxmvvm:NumericToVisibilityConverter x:Key="NumericToVisibilityConverter" Inverse="True" />
            <DataTemplate x:Key="summaryTemplate">
                <ContentControl>
                    <dxg:GridSummaryItem FieldName="{Binding Path=(dxi:DependencyObjectExtensions.DataContext).PropertyName, RelativeSource={RelativeSource Self}}"
                                         SummaryType="Sum" DisplayFormat="n0" Alignment="Left"/>
                </ContentControl>
            </DataTemplate>
    
        </UserControl.Resources>
        <controls:PersistableGridControl x:Name="GridControl"
                                         LayoutPersister="{Binding LayoutPersister}"
                                         CustomUnboundColumnData="OnCustomUnboundColumnData"
                                         MouseDoubleClick="OnMouseDoubleClick" BorderBrush="Transparent" 
                                         GroupSummarySource="{Binding MyColumnsList}"
                                         GroupSummaryGeneratorTemplate="{StaticResource summaryTemplate}"
                                         AutoExpandAllGroups="True" AllowLiveDataShaping="True"
                                         >
            <dxg:GridControl.View >
                <dxg:TableView AllowSorting="False" AllowColumnFiltering="False" GroupSummaryDisplayMode="AlignByColumns" AllowGrouping="True"  ShowGroupPanel="False" AlternateRowBackground="#FFD2DEEF" ShowIndicator="False" BestFitMode="AllRows" AutoWidth="True">
    
    
                </dxg:TableView>
    
            </dxg:GridControl.View>
    
    
        </controls:PersistableGridControl>
    </UserControl>
    • Moved by Bob Ding Thursday, January 25, 2018 6:25 AM third party control
    Wednesday, January 24, 2018 7:05 PM

All replies

  • I see you seem to be using devexpress controls.

    This forum is intended only for questions about Microsoft products.

    Please ask questions related to their controls in devexpress forums.

    .

    In outline I would add an IsEnabled public property to whatever viewmodel is in the observablecollection<t> you're binding itemssource to.

    Bind that to the IsEnabled property of whatever control you're using as a hyperlink.

    Set that false.

    Or

    You could use a mousebinding and in your icommand make canexecute return false when you don't want the right click enabled.

    <whatever.InputBindings>
        <MouseBinding MouseAction="RightClick"
                      Command="{Binding SomeSortOfICommand}"
                     />
    

    You might have to apply that mousebinding via a style.

    Expose the command as a public property of your row's viewmodel.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Wednesday, January 24, 2018 7:46 PM
  • Hi,

    I am afraid  your post is outside of this forum scope of support ,this forum does not support third-party controls. I will move your thread to off-topic forum.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 25, 2018 6:24 AM