Telerik Forums
UI for WPF Forum
3 answers
239 views

Hello,

I'd like to use a DesktopAlert in a WPF MVVM app.

I copy the code from the Telerik WPF app - DesktopAlert Examples - First Look app (email example).

Code:

public class AlertViewModel : BaseViewModel
{
private RadDesktopAlertManager desktopAlertManager;

public AlertViewModel()
{
this.desktopAlertManager = new RadDesktopAlertManager(AlertScreenPosition.BottomRight, 5d);
}

public Action ActivateMainWindowAction { get; set; }
private void OnAlertCommandExecuted(object param)
{            
if (this.ActivateMainWindowAction != null)
{
this.ActivateMainWindowAction.Invoke();
}            
}

public void TestAlert()
{
BitmapImage b = new BitmapImage();
b.BeginInit();
b.UriSource = new Uri("C:\\...\\error.png");
b.EndInit();

this.desktopAlertManager.ShowAlert(new DesktopAlertParameters
{
Header = "Header",
Content = "Content",
Icon = new Image { Source = b, Width = 48, Height = 48 },
IconColumnWidth = 48,
IconMargin = new Thickness(10, 0, 20, 0),
Command = new DelegateCommand(this.OnAlertCommandExecuted),
CommandParameter = "ABC"
});
}
}

public partial class Alert : UserControl
{
public Alert()
{
InitializeComponent();
AlertViewModel vm = ServiceLocator.Current.GetInstance<AlertViewModel>();
vm.ActivateMainWindowAction = new Action(this.ActivateMainWindow);
DataContext = vm;
}

private void ActivateMainWindow()
{
var mainWindow = Application.Current.MainWindow;

if (mainWindow != null)
{
if (mainWindow.WindowState == WindowState.Minimized)
{
mainWindow.WindowState = WindowState.Normal;
}

if (!mainWindow.IsActive)
{
mainWindow.Activate();
}
}
}
}

 

The DesktopAlertParameters command never execute and the alert never show.

Is there something i miss? If i try desktop alert on a new classic WPF app (no mvvm) works withuot problems.

 

Thanks.

 

Nasko
Telerik team
 answered on 22 Feb 2017
4 answers
126 views
Hi,

Is the number of slices in a radial menu configurable?

Sebastien
Dhaval
Top achievements
Rank 1
 answered on 22 Feb 2017
1 answer
115 views

Hi,

Any update on removing the white space from the menu if we are using less then 8 items?
Because it is looking very bad on the UI section.

Our clients want to remove the white space. So any option to do it?

Waiting for your quick reply.

Kalin
Telerik team
 answered on 22 Feb 2017
3 answers
277 views
I've put a RadMaskedNumericInput control onto window. To that I wanted to add validation. Here's the custom class I came up with:

public class ByteValidation : ValidationRule
{
    private byte min = 0;
    private byte max = byte.MaxValue;
 
    //The Minimum and Maximum values are there to restrict how low and how high the
    //stored value can be.
    public byte Minimum
    {
        get { return min; }
        set { min = value; }
    }
 
    public byte Maximum
    {
        get { return max; }
        set { max = value; }
    }
 
    public string ErrorMessage
    { get; set; }
 
    public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
    {
        if (value == null)
        {
            return new ValidationResult(true, null);
        }
 
        byte tmp;
 
        try
        {
            double dTmp = (double)value;
            tmp = (byte)dTmp;
        }
        catch (Exception)
        {
            return new ValidationResult(false, "Invalid value");
        }
 
        if (tmp < min || tmp > max)
        {
            return new ValidationResult(false, ErrorMessage);
        }
 
        return new ValidationResult(true, null);
    }
}

and here's the XAML:

<telerik:RadMaskedNumericInput Mask="##" Margin="550,0,0,0" Grid.Row="1" FontSize="16" VerticalAlignment="Bottom" FontFamily="Century Gothic">
    <telerik:RadMaskedNumericInput.Value>
        <Binding Path="DaysPaidLast30">
            <Binding.ValidationRules>
                <local:ByteValidation Minimum="0" Maximum="30" ErrorMessage="Value must be between 0 and 30." />
            </Binding.ValidationRules>
        </Binding>
    </telerik:RadMaskedNumericInput.Value>
</telerik:RadMaskedNumericInput>

This all works fine.

In testing I discovered that if I put in some invalid numeric data, then I'll get a gold border and a popup message. Is that color standard with the RadMaskedNumericInput? Can that be styled?

xxx
Evgenia
Telerik team
 answered on 21 Feb 2017
1 answer
160 views

When I view the RadGridView, I can hide columns using the IsVissible=false method.  This appears to be ignored when printing.  Is this true and if so, is there another way that I can dynamically cause columns to not be printed?

If all the columns show, it bleeds to a second page and if I force all columns to print on a single page, the font is simply too small to read.

Thanks.

Dilyan Traykov
Telerik team
 answered on 21 Feb 2017
17 answers
727 views

I'm trying to add a tooltiptemplate for the series in my RadCartesianChart. I can't get this to work but I don't see any problem with it.

XAML:

<telerik:ScatterLineSeries x:Key="ToolTipDisplay2">
<telerik:ScatterLineSeries.PointTemplate>
<DataTemplate>
<Ellipse Width="2" Height="2" Fill="Black" />
</DataTemplate>
</telerik:ScatterLineSeries.PointTemplate>
</telerik:ScatterLineSeries>

 

C# code:

... series added...

ScatterLineSeries temp1 = (ScatterLineSeries) this.Resources["ToolTipDisplay2"];
survivalChart.Series[survivalChart.Series.Count() - 1].TooltipTemplate = (DataTemplate) temp1.TooltipTemplate;

 

William
Top achievements
Rank 1
 answered on 21 Feb 2017
2 answers
1.4K+ views

Hi Guys,

I'm struggling with an issue and I can't figure why this goes wrong.

I cannot access my object in the resourcedictionary in my code behind.  What I have is the following
I have a resourcedictionary like this.

 

                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    xmlns:telerikScheduleView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.ScheduleView"
                    xmlns:telerikColorPickers="clr-namespace:Telerik.Windows.Controls.RichTextBoxUI.ColorPickers;assembly=Telerik.Windows.Controls.RichTextBoxUI"
                    xmlns:local="clr-namespace:Proj"
                    xmlns:p="clr-namespace:Proj.Resources"
                    x:Class="Proj.ProductieOrderViewRecources">
 
 
    <DataTemplate x:Key="ProductieOrderViewToolBarTemplate">
        <telerik:RadRichTextBoxRibbonUI x:Name="richTextBoxRibbonUI"

 

this whitin this resourcedictionary
I have a radgridview like this.

<DataTemplate x:Key="ProductieOrderViewMainSectorTemplate">
    <Grid Margin="10">
        <Grid>
            <telerik:RadBusyIndicator x:Name="BusyIndicator" Grid.Row="2" Visibility="{Binding ShowPlanning}" >
                <telerik:RadGridView x:Name="gridViewAdminData"
                                     ItemsSource="{Binding DataRecords}"
                                     RowEditEnded="EditRecord"
                                     DataLoading="LoadData"
                                     SelectionChanged="GridSelectionChanged"
                                     FrozenColumnCount ="5"
                                     AutoGenerateColumns="False"
                                     Deleting="RadGridView_deleting"
                                     SelectedItem="{Binding SelectedPlanning}">
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Artikel}" IsReadOnly="True" />
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Aantal}" />

now I'm trying the access the gridViewAdminData by name in the code behind.

but it won't work at all.
I have this in my code

public partial class ProductieOrderViewRecources : ResourceDictionary
{
    public ProductieOrderViewRecources()
    {
        InitializeComponent();
         
            System.Linq.Expressions.Expression<Func<Proj.Models.productieorder, double>> expression = order => (order.AantalTeProduceren + 10);
            //RadGridView gridViewAdminData = (RadGridView)this["gridViewAdminData"];
            GridViewExpressionColumn column = gridViewAdminData.Columns["TotalValue"] as GridViewExpressionColumn;
            column.Expression = expression;
         
    }
}

but gridViewAdminData won't get recognized. Also enabling the line above gives back a null value.

Does anyone have any idea about how to access this object in the code behind?

thank you

Bart
Top achievements
Rank 1
 answered on 21 Feb 2017
6 answers
90 views

Hello,

I have a VisualizationLayer bound to a collection of objects. I've defined a MapEllipseView for (some of) the objects in the collection via an ItemTemplateSelector.
The issue I have is that when I add items to the collection the ellipses are only rendered on the map at the completion of a zoom animation.

How can I get them to appear straight away after they are added in the collection?

Thanks,
Chris

Petar Mladenov
Telerik team
 answered on 21 Feb 2017
4 answers
360 views

I am trying to bind a few ContextMenu items to the selected appointment's properties, however I can't seem to get to the DataContext of the scheduleview.

<telerik:RadMenuItem Header="Requires Nurse..." IsChecked="{Binding Menu.UIElement.SelectedAppointment.Require_Nurse}" />

I've tried RelativeSource up to the ScheduleGrid, or direct to UIElement and everything gives me the same binding expression error that Schedule_VM doesn't contain a property for Require_Nurse.

Is there any way to bind a context menu item to the appointment?  Even if I get it bound will it actually allow modifying of the property?

Brandon
Top achievements
Rank 1
 answered on 20 Feb 2017
10 answers
533 views

Hello,

I'm working on a WPF application using Prism 5 and Telerik UI for WPF R3 2016. The application loads dinamically 2 separate modules (dll) using UnityContainer and inject them in a RadDocking control as follows:

MainWindow.xaml

<Window.Resources>
        <Style TargetType="telerik:RadDocumentPane">
            <Setter Property="Header" Value="{Binding DataContext.Title}"/>
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <ContentControl VerticalAlignment="Center" HorizontalAlignment="Center"
                                            Margin="0,0,7,0" Content="{Binding}"/>
                            <Button Grid.Column="1" Content="x">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <prism:CloseTabAction/>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </Button>

                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal">
            <Button Content="Toolbar" Command="{Binding ShowToolbarCommand}" Width="50" Height="25" HorizontalAlignment="Left"></Button>
            <Button Content="Home" Command="{Binding ShowHomeCommand}" Width="50" Height="25" HorizontalAlignment="Left"></Button>
        </StackPanel>
        <DockPanel Grid.Row="1" LastChildFill="True">
            <telerikDocking:RadDocking x:Name="Docking" Background="Transparent"
                                      BorderThickness="0">
                <telerikDocking:RadDocking.DocumentHost>
                    <telerikDocking:RadSplitContainer >
                        <telerikDocking:RadPaneGroup regions:RegionManager.RegionName="{x:Static model:RegionNames.ContentRegion}"/>
                    </telerikDocking:RadSplitContainer>
                </telerikDocking:RadDocking.DocumentHost>
                <telerikDocking:RadSplitContainer MaxWidth="400" Width="175" MinWidth="175" InitialPosition="DockedLeft">
                    <telerikDocking:RadPaneGroup>
                        <telerikDocking:RadDocumentPane CanUserClose="False" PaneHeaderVisibility="Collapsed"
                                regions:RegionManager.RegionName="{x:Static model:RegionNames.LeftRegion}">
                        </telerikDocking:RadDocumentPane>
                    </telerikDocking:RadPaneGroup>
                </telerikDocking:RadSplitContainer>
            </telerikDocking:RadDocking>
        </DockPanel>
    </Grid>

CloseTabAction.cs

public class CloseTabAction : TriggerAction<Button>
    {
        protected override void Invoke(object parameter)
        {
            var args = parameter as RoutedEventArgs;
            if (args == null)
                return;
            var tabItem = FindParent<RadPane>(args.OriginalSource as DependencyObject);
            if (tabItem == null)
                return;
            var tabControl = FindParent<RadPaneGroup>(tabItem);
            if (tabControl == null)
                return;

            IRegion region = RegionManager.GetObservableRegion(tabControl).Value;
            if (region == null)
                return;
            RemoveItemFromRegion(tabItem.Content, region);
        }

        void RemoveItemFromRegion(object item, IRegion region)
        {
            var navigationContext = new NavigationContext(region.NavigationService, null);
            if (CanRemove(item, navigationContext))
            {
                InvokeOnNavigatedFrom(item, navigationContext);
                region.Remove(item);
            }
        }

        void InvokeOnNavigatedFrom(object item, NavigationContext navigationContext)
        {
            var navigationAwareItem = item as INavigationAware;
            if (navigationAwareItem != null)
                navigationAwareItem.OnNavigatedFrom(navigationContext);
            var frameworkElement = item as FrameworkElement;
            if (frameworkElement != null)
            {
                INavigationAware navigationAwareDataContext = frameworkElement.DataContext as INavigationAware;
                if (navigationAwareDataContext != null)
                {
                    navigationAwareDataContext.OnNavigatedFrom(navigationContext);
                }
            }
        }

        bool CanRemove(object item, NavigationContext navigationContext)
        {
            bool canRemove = true;
            var confirmRequestItem = item as IConfirmNavigationRequest;
            if (confirmRequestItem != null)
            {
                confirmRequestItem.ConfirmNavigationRequest(navigationContext, result =>
                {
                    canRemove = result;
                });
            }
            var frameworkElement = item as FrameworkElement;
            if (frameworkElement != null && canRemove)
            {
                IConfirmNavigationRequest confirmRequestDataContext = frameworkElement.DataContext as IConfirmNavigationRequest;
                if (confirmRequestDataContext != null)
                {
                    confirmRequestDataContext.ConfirmNavigationRequest(navigationContext, result =>
                    {
                        canRemove = result;
                    });
                }
            }
            return canRemove;
        }

        static T FindParent<T>(DependencyObject child) where T : DependencyObject
        {
            DependencyObject parentObject = VisualTreeHelper.GetParent(child);
            if (parentObject == null)
                return null;
            var parent = parentObject as T;
            if (parent != null)
                return parent;
            return FindParent<T>(parentObject);
        }
    }

I've overrided Prism ScopedRegionNavigationContentLoader in order to allow views injections using navigation to create ScopedRegions:

public class ScopedRegionNavigationContentLoader: IRegionNavigationContentLoader
    {
        private readonly IServiceLocator serviceLocator;

        /// <summary>
        /// Initializes a new instance of the <see cref="RegionNavigationContentLoader"/> class with a service locator.
        /// </summary>
        /// <param name="serviceLocator">The service locator.</param>
        public ScopedRegionNavigationContentLoader(IServiceLocator serviceLocator)
        {
            this.serviceLocator = serviceLocator;
        }

        /// <summary>
        /// Gets the view to which the navigation request represented by <paramref name="navigationContext"/> applies.
        /// </summary>
        /// <param name="region">The region.</param>
        /// <param name="navigationContext">The context representing the navigation request.</param>
        /// <returns>
        /// The view to be the target of the navigation request.
        /// </returns>
        /// <remarks>
        /// If none of the views in the region can be the target of the navigation request, a new view
        /// is created and added to the region.
        /// </remarks>
        /// <exception cref="ArgumentException">when a new view cannot be created for the navigation request.</exception>
        public object LoadContent(IRegion region, NavigationContext navigationContext)
        {
            if (region == null) throw new ArgumentNullException("region");
            if (navigationContext == null) throw new ArgumentNullException("navigationContext");

            string candidateTargetContract = this.GetContractFromNavigationContext(navigationContext);

            var candidates = this.GetCandidatesFromRegion(region, candidateTargetContract);

            var acceptingCandidates =
                candidates.Where(
                    v =>
                    {
                        var navigationAware = v as INavigationAware;
                        if (navigationAware != null && !navigationAware.IsNavigationTarget(navigationContext))
                        {
                            return false;
                        }

                        var frameworkElement = v as FrameworkElement;
                        if (frameworkElement == null)
                        {
                            return true;
                        }

                        navigationAware = frameworkElement.DataContext as INavigationAware;
                        return navigationAware == null || navigationAware.IsNavigationTarget(navigationContext);
                    });


            var view = acceptingCandidates.FirstOrDefault();

            if (view != null)
            {
                return view;
            }

            view = this.CreateNewRegionItem(candidateTargetContract);

            region.Add(view, null, CreateRegionManagerScope(view));

            return view;
        }

        private bool CreateRegionManagerScope(object view)
        {
            bool createRegionManagerScope = false;

            var viewHasScopedRegions = view as ICreateRegionManagerScope;
            if (viewHasScopedRegions != null)
                createRegionManagerScope = viewHasScopedRegions.CreateRegionManagerScope;

            return createRegionManagerScope;
        }

        /// <summary>
        /// Provides a new item for the region based on the supplied candidate target contract name.
        /// </summary>
        /// <param name="candidateTargetContract">The target contract to build.</param>
        /// <returns>An instance of an item to put into the <see cref="IRegion"/>.</returns>
        protected virtual object CreateNewRegionItem(string candidateTargetContract)
        {
            object newRegionItem;
            try
            {           
                newRegionItem = this.serviceLocator.GetInstance<object>(candidateTargetContract);
            }
            catch (ActivationException e)
            {
                throw new InvalidOperationException(
                    string.Format(CultureInfo.CurrentCulture, "Cannot create navigation target", candidateTargetContract),
                    e);
            }
            return newRegionItem;
        }

        /// <summary>
        /// Returns the candidate TargetContract based on the <see cref="NavigationContext"/>.
        /// </summary>
        /// <param name="navigationContext">The navigation contract.</param>
        /// <returns>The candidate contract to seek within the <see cref="IRegion"/> and to use, if not found, when resolving from the container.</returns>
        protected virtual string GetContractFromNavigationContext(NavigationContext navigationContext)
        {
            if (navigationContext == null) throw new ArgumentNullException("navigationContext");

            var candidateTargetContract = UriParsingHelper.GetAbsolutePath(navigationContext.Uri);
            candidateTargetContract = candidateTargetContract.TrimStart('/');
            return candidateTargetContract;
        }

        /// <summary>
        /// Returns the set of candidates that may satisfiy this navigation request.
        /// </summary>
        /// <param name="region">The region containing items that may satisfy the navigation request.</param>
        /// <param name="candidateNavigationContract">The candidate navigation target as determined by <see cref="GetContractFromNavigationContext"/></param>
        /// <returns>An enumerable of candidate objects from the <see cref="IRegion"/></returns>
        protected virtual IEnumerable<object> GetCandidatesFromRegion(IRegion region, string candidateNavigationContract)
        {
            if (region == null) throw new ArgumentNullException("region");
            return region.Views.Where(v =>
                string.Equals(v.GetType().Name, candidateNavigationContract, StringComparison.Ordinal) ||
                string.Equals(v.GetType().FullName, candidateNavigationContract, StringComparison.Ordinal));
        }
    }

 

Everything works fine for creation / add RadPanes except Closing and Moving event.

On Close, the the exception is: An unhandled exception of type 'System.InvalidCastException' occurred in Telerik.Windows.Controls.Docking.dll

Additional information: Unable to cast object of type 'ModuleA.Views.ModuleAHomeView' to type 'Telerik.Windows.Controls.RadPane'.

but hostControl is a valid RadPaneGroup and Items collection DO contain ModuleA.Views.ModuleAHomeView

On Move,  I've got a NullReferenceExceltopn at Telerik.Windows.Controls.RadPane.OnHeaderMouseLeftButtonDown(Object sender, MouseButtonEventArgs e)

 

Any help would be highly appreciated.

Best regards,

Alin Halatiu

Alin
Top achievements
Rank 1
 answered on 20 Feb 2017
Narrow your results
Selected tags
Tags
GridView
General Discussions
Chart
RichTextBox
Docking
ScheduleView
ChartView
TreeView
Diagram
Map
ComboBox
TreeListView
Window
RibbonView and RibbonWindow
PropertyGrid
DragAndDrop
TabControl
TileView
Carousel
DataForm
PDFViewer
MaskedInput (Numeric, DateTime, Text, Currency)
AutoCompleteBox
DatePicker
Buttons
ListBox
GanttView
PivotGrid
Spreadsheet
Gauges
NumericUpDown
PanelBar
DateTimePicker
DataFilter
Menu
ContextMenu
TimeLine
Calendar
Installer and Visual Studio Extensions
ImageEditor
BusyIndicator
Slider
Expander
TileList
PersistenceFramework
DataPager
Styling
TimeBar
OutlookBar
TransitionControl
Book
FileDialogs
ToolBar
ColorPicker
TimePicker
SyntaxEditor
MultiColumnComboBox
VirtualGrid
Wizard
ExpressionEditor
NavigationView (Hamburger Menu)
DesktopAlert
WatermarkTextBox
BarCode
SpellChecker
DataServiceDataSource
EntityFrameworkDataSource
RadialMenu
ChartView3D
Data Virtualization
BreadCrumb
ProgressBar
Sparkline
LayoutControl
TabbedWindow
ToolTip
CloudUpload
ColorEditor
TreeMap and PivotMap
EntityFrameworkCoreDataSource (.Net Core)
HeatMap
Chat (Conversational UI)
VirtualizingWrapPanel
Calculator
NotifyIcon
TaskBoard
TimeSpanPicker
BulletGraph
WebCam
CardView
DataBar
Licensing
FilePathPicker
PasswordBox
Rating
SplashScreen
Accessibility
Callout
CollectionNavigator
Localization
AutoSuggestBox
HighlightTextBlock
Security
TouchManager
StepProgressBar
VirtualKeyboard
Badge
OfficeNavigationBar
ExpressionParser
CircularProgressBar
SvgImage
PipsPager
SlideView
AI Coding Assistant
+? more
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?