Label does not change content - wpf

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.

Related

Image with Multiple Clickable Areas

I have an image that I want various parts of to be clickable. I found a comment in the question below mentioning this was possible with Expression Designer. I haven't been able to find a guide on how to do this. I understand that I have to export the image from Designer to Visual Studio. Is there a better way of achieving this or how do I go about creating the xaml for these clickable sections?
best way for clickable image map in wpf
Personally I'd use the second answer to that question i.e. do something like this:
<Canvas>
<Image Source="background.png"/>
<Ellipse Canvas.Left="82" Canvas.Top="88" Width="442" Height="216" Fill="Transparent" Cursor="Hand" MouseDown="Ellipse_MouseDown_1"/>
<Ellipse Canvas.Left="305" Canvas.Top="309" Width="100" Height="50" Fill="Transparent" Cursor="Hand" MouseDown="Ellipse_MouseDown_2"/>
</Canvas>
Then you can drag and resize the shapes in DevStudio using it's XAML editor's design mode.

WPF Control remove focus and hover effect (FocusVisualStyle?!)

I am trying to remove the nasty looking effect on controls when hovering or focusing.
This seems not to work:
FocusVisualStyle="{x:Null}"
And this is what I got so far:
<ComboBox Grid.Row="2" HorizontalAlignment="Right" Background="Transparent" BorderBrush="#FFE87E00" FocusVisualStyle="{x:Null}"/>
Thanks in advance!
Look at the control template, you should be able to manipulate what occurs when visual states changes from there.

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

ImageButton in Silverlight 3?

For our .NET project this year we have to create a website in Silverlight.
Now I have been getting along nicely utilizing the grid, making gridrows and colums, but I have got to the part where I have to create navigation buttons.
So I decided to go for the following look of the buttons:
Now, when I add a button to my project and I give it the background of that image, this happens.
I have looked at other methods to create an image button but those involve putting an image INSIDE the button using a stackpanel. I tried that and it looks really bad.
This is the code the button generated:
<Button Content="Button" Height="40" Name="button1" Width="125">
<Button.Background>
<ImageBrush ImageSource="/OndernemersAward;component/Images/button.png" Stretch="Fill" />
</Button.Background>
</Button>
I don't know what's going on here and I hope somebody can help me.
Thanks, Thomas
Putting an image inside the button is the best way to go. You can just have an image inside a button, or you could put a StackPanel inside and arrange other content as you see fit. You can also get rid of the border and background brushes on the button so that it is just your image and nothing else. Try this code:
<Button Height="40" Name="button1" Width="125" BorderBrush="{x:Null}" Background="{x:Null}" IsHitTestVisible="False">
<Image Source = "/OndernemersAward;component/Images/button.png"/>
</Button>
That will make a button that is just your image with no other borders, or colors. You can tweak the other settings as you see fit. Note that in order to use the image as the button, you have to delete the Content tag, since the inside of the <Button> takes the place of it.
I ultimately solved this by using blent. I created an image and there is a control there that can transform the image to a button.

ScrollViewer Content size change then ScrollToOffset not working

I am using a scrollviewer to display an Image within it.
<ScrollViewer Name="scrollViewer1" Height="500" Width="500" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Padding="0" >
<Image x:Name="img1" Width="100" Source="/MyApp;component/Images/Test.jpg" />
</ScrollViewer>
But when I re-size the image in code, and immediately use the scrollViewer.ScrollToHorizontalOffset() (to reposition the image) it does not work :
img1.Width = 1000;
scrollViewer1.ScrollToHorizontalOffset(500);
I verified the ScrollableWidth property after the img1.Width = 1000 indeed it is not updated yet. So I used the UpdateLayout() right after I resize the image, great now the ScrollableWidth is updated :
img1.Width = 1000;
scrollViewer1.UpdateLayout();
scrollViewer1.ScrollToHorizontalOffset(500);
but the ScrollToHorizontalOffset is still not working. If I do it afterwards, on another user button click it works though. :/
Anyone has a clue?
Nevermind... My error, the example above works. In my project I was basing the ScrollToHorizontalOffset on the img1.ActualWidth which was not updated.
Sorry :/

Resources