error when adding image to wpf toolbar button - wpf

I am getting this error: "value does not fall within the expected range" when I try to add code to add an image for a button in a wpf app in VB.net. I don't seem to know what to do or what is wrong? Here is the XAML code that gives the error:
<ToolBarTray Height="33" Name="ToolBarTray1" VerticalAlignment="Top">
<ToolBar Background="Cyan" Height="33" Band="1" BandIndex="1" ToolBarTray.IsLocked="True">
<Button><Image Source="new.bmp"/></Button>
</ToolBar>
</ToolBarTray>
The part that is underlined showing the error is <Image Source="new.bmp"/> . Someone tell me what is not right.

I'm not sure how your project is set up but read this http://msdn.microsoft.com/en-us/library/aa970069.aspx

Related

Image control not showing the image when run code

Quick summary - i add image control on simple wpf window and set image .while design time it shows and but in run time its doesn't and not showing any exception
<Grid>
<Image Name ="im1" HorizontalAlignment="Left" Height="50" Margin="127,147,0,0"VerticalAlignment="Top" Width="50" Source="pack://siteoforigin:,,,/Resources/chetas logo.bmp" />
</Grid>'
I got it .. when i set my image build in action property as embedded resource

WPF: Tab GroupBox item appears and disappears after cleaning & building

Using VS2012 and .NET 4.0, I have the following block of code in a UserControl:
<GroupBox Name="LocalGroup">
<GroupBox.Header>
<TextBlock FontWeight="Bold"
Text="Local Rules">
</TextBlock>
</GroupBox.Header>
<StackPanel Margin="20,8,10,0"
Orientation="Vertical" >
<local:LocalRulesHeader />
</StackPanel>
</GroupBox>
When I build the program the line '' gets the blue squiggly underline with the error message of
Error 16 The component 'ToolLibrary.LocalRulesHeader' does not have a resource
identified by the URI '/ToolLibrary;component/xamlclasses/localrulesheader.xaml'.
Yet when I clean the project the blue squiggly line disappears and the LocalRulesHeader is displayed in the GroupBox as expected. I do a build and the blue squiggly line and error message reappear.
I have tried cleaning the project as well as shutting down VS and restarting to no avail.
Has anyone experienced this and found a way to resolve?

Background Image of Button not showing in WPF

I have program in which I have lots of buttons. Each of button has background set as
<Button x:Name="mybutton" HorizontalAlignment="Left" Height="30" Margin="76,110,0,0" VerticalAlignment="Top" Width="25" Click="some_click">
<Button.Background>
<ImageBrush ImageSource="Resource/button_picture.png"/>
</Button.Background>
</Button>
Image is showing as background in .xaml when program not running but when i run application image is not there as background of button. How do i debug this background in button ? Is there any goofy error that is there?
Let's make sure we have the following properties set right in your scenario
1) Build Action -> Resource
2) Copy to Output Directory -> Do not copy
3) Instead of using the relative path for image source, try using a full path to the image like this (I say this because I don't know where the image resource is located in your project, using relative path is perfectly normal in WPF)
<Image Source="pack://application:,,,/AssemblyNameContainingImageResource;component/Resource/button_picture.png" />
You need to change the code like this
<Button x:Name="mybutton" HorizontalAlignment="Left" Height="30" Margin="76,110,0,0" VerticalAlignment="Top" Width="25" Click="some_click">
<Image Source="Resource/button_picture.png"/>
</Button>
Change the Build Action of button_picture.png to Resource if it is content. Also check the Copy to output directory property value

Label does not change content

I have WPF app with label MainWindow.xaml:
<Label Grid.Row="1" Margin="0,17,0,16" Name="lblLoadDriver" VerticalAlignment="Center" HorizontalAlignment="Left" Height="10" Width="10"></Label>
In MainWindow.xaml.cs there is code, after button click:
lblLoadDriver.Content = ""+DriverInstance.GetType().ToString();
When i debug, I put the mouse over the value of lblLoadDriver browse under "base" section and see content is AS-I-NEED.. i see the text ok, but it didnt change the text on GUI.
Why is this ? Do i need to refresh gui or something ?
thanks.
Perhaps because of Width="10"?
Also Height="10" is a strange idea.

ImageButton in WPF

Hy!!
I added a png to the debug dic. Now my Xaml Code:
<Button Height="23" HorizontalAlignment="Left" Margin="160,249,0,0" Name="button1" VerticalAlignment="Top" Width="57" ">
<Image Source="\back.png"></Image>
</Button>
The image won'T be found. I read some tutorials about a image in a button, but they all speak about resources etc.
Please write your answer step by step i am very new to WPF
Add the file to the solution. Open the image properties by right click on an image and make sure the build action for image is set to Resource.
You have to add the image to the solution and give the path Like and Set its property BuildAction to Resource
<Image Margin="2" Source="/ApplicationName;component/FolderName/back.png" />

Resources