This is a migrated thread and some comments may be shown as answers.

Set Icon programmatically

5 Answers 648 Views
Window
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 18 Sep 2010, 08:20 PM
Hello

How do I set the top left form icon form via code?
I have attached a sample section of code and
given the Image a name of imgFormIcon but
I cannot reference via code?

Regards,
Simon

<telerik:RadWindow x:Class="Designer.Forms.LoginWindow"<br>        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"<br>        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br>        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br>        Height="202" Width="406" FontFamily="Verdana" WindowStartupLocation="CenterScreen" Name="frmLogin" Loaded="frmLogin_Loaded" Header="Login"><br>    <telerik:RadWindow.IconTemplate><br>        <DataTemplate><br>            <Image Source="" Stretch="UniformToFill" MaxHeight="16" MaxWidth="16" Name="imgFormIcon" /><br>        </DataTemplate><br>    </telerik:RadWindow.IconTemplate><br>    <Grid><br>        <Grid.RowDefinitions><br>            <RowDefinition Height="12" /><br>            <RowDefinition Height="24" /><br>            <RowDefinition Height="36" /><br>            <RowDefinition Height="24" /><br>            <RowDefinition Height="24" /><br>            <RowDefinition Height="12" /><br>            <RowDefinition Height="24" /><br>            <RowDefinition Height="212*" /><br>        </Grid.RowDefinitions><br>        <Grid.ColumnDefinitions><br>            <ColumnDefinition Width="70" /><br>            <ColumnDefinition Width="120" /><br>            <ColumnDefinition Width="240" /><br>        </Grid.ColumnDefinitions><br>        <Image Height="48" HorizontalAlignment="Left" Margin="12,0,0,0" Name="imgIcon" Stretch="Fill" VerticalAlignment="Top" Width="48" Grid.Row="1" Grid.RowSpan="2" /><br>        <Label Content="Login Credentials:" Grid.Column="1" Grid.Row="1" Height="24" HorizontalAlignment="Left" Margin="0,0,0,0" Name="label1" VerticalAlignment="Top" FontSize="10" FontWeight="Bold" /><br>        <Label Content="Authentication:" Grid.Column="1" Grid.Row="2" Height="24" HorizontalAlignment="Left" Margin="0,0,0,0" Name="label2" VerticalAlignment="Top" FontSize="10" /><br>        <Label Content="Username:" Grid.Column="1" Grid.Row="3" Height="24" HorizontalAlignment="Left" Margin="0,0,0,0" Name="label3" VerticalAlignment="Top" FontSize="10" /><br>        <Label Content="Password:" Grid.Column="1" Grid.Row="4" Height="24" HorizontalAlignment="Left" Margin="0,0,0,0" Name="label4" VerticalAlignment="Top" FontSize="10" /><br>        <RadioButton Content="Windows Authentication" Grid.Column="2" Grid.Row="2" Grid.RowSpan="2" Height="16" HorizontalAlignment="Left" Margin="0,4,0,0" Name="rdbWindowsAuthentication" VerticalAlignment="Top" FontSize="10" GroupName="Authentication" IsChecked="True" /><br>        <RadioButton Content="Standard Authentication" Grid.Column="2" Grid.Row="2" Grid.RowSpan="2" Height="16" HorizontalAlignment="Left" Margin="0,20,0,0" Name="rdbStandardAuthentication" VerticalAlignment="Top" FontSize="10" GroupName="Authentication" /><br>        <telerik:RadMaskedTextBox Grid.Column="2" Grid.Row="3" HorizontalAlignment="Left" Name="txtUsername" VerticalAlignment="Top" Width="180" MaskType="None" Mask="" FontSize="10" /><br>        <telerik:RadMaskedTextBox Grid.Column="2" Grid.Row="4" HorizontalAlignment="Left" Name="txtPassword" VerticalAlignment="Bottom" Width="180" MaskedText="" Margin="0,0,0,2" MaskType="None" Mask="" FontSize="10" /><br>        <telerik:RadButton Content="Login" Grid.Column="2" Grid.Row="6" Height="22" Width="75" HorizontalAlignment="Left" Margin="0,0,0,0" Name="cmdLogin" VerticalAlignment="Top" IsDefault="True" /><br>        <telerik:RadButton Content="Close" Grid.Column="2" Grid.Row="6" Height="22" Width="75" HorizontalAlignment="Left" Margin="80,0,0,0" Name="cmdClose" VerticalAlignment="Top" IsCancel="True" /><br>    </Grid><br></telerik:RadWindow><br>

5 Answers, 1 is accepted

Sort by
0
Dani
Telerik team
answered on 20 Sep 2010, 07:59 AM
Hi Simon,

Thank you for you inquiry.

Please, review this help article on the Window Icon topic. I think it does contain the information you need. If you have any difficulties or further questions, please get back to us, we will gladly assist you.


Best wishes,
Dani
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Simon
Top achievements
Rank 1
answered on 20 Sep 2010, 08:37 AM
Hello Dani

I managed to get it to work on a normal window however I prefer to use the RadWindow so I will try what you have sent.
How do I format the non Telerik WPF controls in the RadWindow like a I do in the standard Window? I use this code below
to do it on the standard WPF window.

    <Window.Resources>
        <!-- this is for global style for controls -->
        <Style TargetType="Window" BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Office_BlueTheme, ElementType=Window}}" />
        <Style TargetType="TextBox" BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Office_BlueTheme, ElementType=TextBox}}" />
        <Style TargetType="PasswordBox" BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Office_BlueTheme, ElementType=PasswordBox}}" />
        <Style TargetType="ListBox" BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Office_BlueTheme, ElementType=ListBox}}" />
        <Style TargetType="ListBoxItem" BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Office_BlueTheme, ElementType=ListBoxItem}}" />
        <Style TargetType="Button" BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Office_BlueTheme, ElementType=Button}}" />
        <Style TargetType="RadioButton" BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Office_BlueTheme, ElementType=RadioButton}}" />
        <Style TargetType="CheckBox" BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Office_BlueTheme, ElementType=CheckBox}}" />
    </Window.Resources>


Regards,
Simon
0
Simon
Top achievements
Rank 1
answered on 20 Sep 2010, 09:13 AM
I tried via code again and I am getting the type.ToString() being added to the header of the RadWindow.
I did try this originally before IconTemplate in XAML.
0
Dani
Telerik team
answered on 22 Sep 2010, 04:56 PM
Hello Simon,

Thank you for your reply.

If you are getting the string of the image, rather than the image itself, you should set the Source of the Image. You can use the approach from the article I posted:

radWindow.Icon = new Image() 
   Source = new BitmapImage( new Uri( "/Images/WindowIcon.png", UriKind.Relative ) ) 
};

or you can do that in XAML with an IconTemplate with the Image Soure set:

<DataTemplate x:Key="WindowIconTemplate">
      <Image Source="/Images/WindowIcon.png"
             Stretch="None" />
  </DataTemplate>

If you are still unable to visualize the icon, the problem must be somewhere else. I would like to ask you to send a sample which illustrates this behavior so that we can help you.

On your question about customizing non-Telerik controls, I am afraid there is hardly any way to apply our themes to native Windows controls.  Telerik themes are not designed to work with non-Telerik controls.

Our themes contain resources for Telerik controls with only few exceptions - ListBox, ScrollViewer, TextBox. For these controls there are no equivalents among Telerik controls, so we have created Styles for them in order to use them in a consistent way in our themes.

Looking forward to your reply.

Sincerely yours,
Dani
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Simon
Top achievements
Rank 1
answered on 24 Sep 2010, 07:36 AM
Perfect. It worked, thanks!
Tags
Window
Asked by
Simon
Top achievements
Rank 1
Answers by
Dani
Telerik team
Simon
Top achievements
Rank 1
Share this question
or