How can I edit a locked file in Visual Studio? - c#

I have a xaml file that I try to edit, but after I make the change and I run the code I see a little sign of lock in the name of the file. The change is not made,
how can I change it?
<Menu Grid.ColumnSpan="6" IsEnabled="False">
<MenuItem Header="_FILE" FontSize="20" Height="25" Width="310" Padding="30,0,0,0">
<MenuItem Header="_Open_file..." Click="Open_file_Click" FontSize="20"></MenuItem>
<MenuItem Header="_Open_folder.." Click="Open_folder_Click" FontSize="20"></MenuItem>
<MenuItem Header="_open_with_server" Click="open_with_server" FontSize="20"></MenuItem>
<MenuItem Header="_open_with_server" Click="open_with_server" FontSize="20"></MenuItem>
<MenuItem Header="_add_song_to_server" Click="add_song_to_server" FontSize="20"
</MenuItem>
<Separator></Separator>
<MenuItem Header="Exit" Click="CloseApp_click" FontSize="25"></MenuItem>
<ListBox Name="lbFiles" />
</MenuItem>
This is the code I want to edit.

Is the program still running? When I start to debug, I get a lock symbol on the file (very briefly) while the project is building. Depending on your settings/version, the lock may also be applied while the code is running.

i deleted and download visual studio 2019 and its finaly work
this is extremely solution but it work.

Related

CheckBoxes "stealing" bitmaps from each other [duplicate]

I have a MenuItem like below
<MenuItem Header="Edit">
<MenuItem Header="Copy Direct Link" Icon="{StaticResource CopyIcon}" Command="{Binding CopyImageCommand}" />
<MenuItem Header="Copy Image Data" Icon="{StaticResource CopyIcon}" Command="{Binding CopyImageDataCommand}" />
<MenuItem Header="Paste" Icon="{StaticResource PasteIcon}" Command="{Binding PasteImageCommand}" />
</MenuItem>
Notice the 1st 2 items use the same icon, I get something like below
I tried removing the 2nd item,
<MenuItem Header="Edit">
<MenuItem Header="Copy Direct Link" InputGestureText="Ctrl+C" Icon="{StaticResource CopyIcon}" Command="{Binding CopyImageCommand}" />
<!--<MenuItem Header="Copy Image Data" InputGestureText="Ctrl+Alt+C" Icon="{StaticResource CopyIcon}" Command="{Binding CopyImageDataCommand}" />-->
<MenuItem Header="Paste" InputGestureText="Ctrl+P" Icon="{StaticResource PasteIcon}" Command="{Binding PasteImageCommand}" />
</MenuItem>
then I got something like
How can I reuse Icons?
See this question
An Image can only have one parent so it will be moved from the first MenuItem to the second. You can add the x:Shared attribute like this
<Window.Resources>
<Image x:Key="CopyIcon" x:Shared="False" Source="..." />
</Window.Resources>
From msdn
x:Shared Attribute
When set to false, modifies WPF
resource-retrieval behavior so that
requests for the attributed resource
create a new instance for each request
instead of sharing the same instance
for all requests.
You're most likely declaring CopyIcon as Image type in your resource, something like this:
<Window.Resources>
<Image x:Key="CopyIcon" Source="yourcopyicon.ico"/>
</Window.Resources>
So, the root cause of the problem is, Image is a visual element, since it derives from FrameworkElement (which is a visual element), and a visual element cannot have more than one parent at the same time. That is why the first MenuItem is not showing the icon, since the second MenuItem reset the parent of CopyIcon, making itself parent of the CopyIcon.
Hope this explanation is helpful to you. Now follow what Meleak has said in his response. :-)
Try the following:
<MenuItem Header=“Paste“ >
<MenuItem.Icon><Image Height=“16“ Width=“16“ Source=“paste.jpg“ /></MenuItem.Icon>
</MenuItem>

Why isnt my WPF menuItem Icon showing?

I can see my Icon in Designer View, but when I run the program it disappears. What am i missing?
EDIT: The Icon itself is 25 by 25 pixels
<DockPanel>
<Menu DockPanel.Dock="Top" HorizontalAlignment="Right" Background="Transparent">
<MenuItem Header="Help">
<MenuItem.Icon>
<Image Source="Resources/Help.png" />
</MenuItem.Icon>
<MenuItem Header="About" />
<MenuItem Header="Update TechTools" />
</MenuItem>
</Menu>
</DockPanel>
You need to set properties on your Help.png file. Righ-click on it, select properties. You want Build action to "Content" and Copy to output directory either Copy Always or Copy if Newer.
You can also consider setting it as Resource, which will embedd it in the program itself.

Putting a drop shadow on a menu item box

This is my first attempt at creating an application, so apologies if my questions are misformed or misplaced.
First a question of terminology: when you click on 'file' in a menu bar and a little box appears below with options like 'quit' and 'save,' what's this box called? Is this just called a 'context menu'?
Second: how can I put a drop shadow on this box? I've seriously been tinkering and googling for the longest time with no luck. For some reason the default in visual studio express 2013, at least as I'm using it, seems to be no shadow, which looks pretty odd imo. Here's the relevant XAML:
<Menu x:Name="MenuBar" HorizontalAlignment="Stretch" Height="27" Margin="-20,-36,140.4,0" VerticalAlignment="Top" Width="Auto" Foreground="Black" RenderTransformOrigin="0.5,0" Background="#FFE5E5E5">
<MenuItem x:Name="File" Header="File" Height="27" Width="39" TextOptions.TextHintingMode="Animated" Foreground="#FF323334" BorderThickness="0" BorderBrush="{x:Null}" Margin="1,0,4,4" Padding="6,0">
<MenuItem x:Name="Save" Header="Save" HorizontalAlignment="Left" Width="139.2" Click="Save_Click"/>
<MenuItem Header="Quit" HorizontalAlignment="Left" Width="139.2" Click="MenuItem_Click" Background="{x:Null}" BorderBrush="{x:Null}" UseLayoutRounding="False"/>
</MenuItem>
</Menu>
Thanks in advance for any help!
EDIT: I ended up getting my answer elsewhere.

Adding drop shadow on a menu item box

This is my first attempt at creating an application, so apologies if my questions are misformed or misplaced.
When you click on 'file' in a menu bar and a little box appears below with options like 'quit' and 'save,' how do I put a drop shadow on this box? I've seriously been tinkering and googling for the longest time with no luck. I feel like I've exhausted the options in visual studio and tried various code in my xaml. Here's the relevant XAML:
<Menu x:Name="MenuBar" HorizontalAlignment="Stretch" Height="27" Margin="-20,-36,140.4,0" VerticalAlignment="Top" Width="Auto" Foreground="Black" RenderTransformOrigin="0.5,0" Background="#FFE5E5E5">
<MenuItem x:Name="File" Header="File" Height="27" Width="39" TextOptions.TextHintingMode="Animated" Foreground="#FF323334" BorderThickness="0" BorderBrush="{x:Null}" Margin="1,0,4,4" Padding="6,0">
<MenuItem x:Name="Save" Header="Save" HorizontalAlignment="Left" Width="139.2" Click="Save_Click"/>
<MenuItem Header="Quit" HorizontalAlignment="Left" Width="139.2" Click="MenuItem_Click" Background="{x:Null}" BorderBrush="{x:Null}" UseLayoutRounding="False"/>
</MenuItem>
</Menu>
Thanks in advance for any help!
EDIT: I ended up getting my answer eslewhere
You just need to create your own Template
here's a link on how to ovveride the default MenuItem Style

How to use .ico as image source for Context menu

This problem is similar to others I have seen here, but none answer the exact question I have.
Code:
<Grid Background="White">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Test">
<MenuItem.Icon>
<Image Source="../Resources/cut_16.ico"></Image>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Grid.ContextMenu>
</Grid>
cut_16.ico is in the correct format and directory and is set to "Resource" for Build Action.
The problem is that at run-time, I get a System.IO.IOException and the icon does not show up.
If I use a .png, it shows up fine, but I have an .ico I need to use.
The text for the menu does show up, however.
I have code to convert a .ico to an image source in code-behind, but I would like to do it in XAML.
Any ideas? Thanks!!

Categories

Resources