|
It's probably not "MVVM".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Huh? That's even momre confusing
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
I'm trying to create a ValueConverter in .Net Core 6, except I can't seem to find the System.Windows.Data namespace, where IValueConveter lives.
What am I missing??
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
|
Hi everybody,
I want to make an overlay above an app or capturing this app into my window. I think i will use an opengl library i thougth to work with
glfw but the feature that allow mouse passtrough is for the 3.4 version, and current is 3.3.8.
The best way for me were to run the window i want directly inside my own window, and control it for fullscreen and other things. I'm not habit with linux, i know on w10 a lot of possibilities were removed for security reason.
My work is on ArchLinux to be more accurate, i use lxde but if possible i prefer to avoid a "desktop environment"...
Thx !
|
|
|
|
|
I'm still trying to get my Navigation Control. The repo is here[^].
Thanks to @RichardDeeming for all your help so far. I wouldn't have made it this far without your help.
So the Navigataion Container contains one or more Navigation Panes. When a pane is expanded, I want its loading to begin after it is expanded. The pane should expand, then the user sees the circular progress indicator while the list is loading. Then, when the results are returned, the circular progress indicator should go away and the results displayed.
If you run the app now, and expand a section, you'll see that it doesn't expand until it's after it's done loading.
I could use another pair of eyes on this.
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
I have created a progress unit control that show a progress in my WPF application and it looks like this:
https://pasteboard.co/peNn9PiguyNC.png
The way I have done this is adding a ListView in my main application view that has a higher ZIndex than the other controls. This essentially overlays all controls, but does not react hit tests and is not visible.
<ListView x:Name="ProgressListView" Grid.Row="1" Grid.RowSpan="2" ItemsSource="{Binding ProgressCollection}" Background="Transparent" Panel.ZIndex="10" IsHitTestVisible="False">
</ListView>
I have most of the WPF code here, but if you need it, I can post it
This works as you can see from the picture. If you look at the picture, there is a close image which is implemented this way:
<Button Grid.Row="0" Grid.Column="1"
Content="{wpf:MaterialIconExt Kind=WindowClose}"
Command="{Binding CloseProgressCommand}"
Style="{StaticResource ProgressButtonStyle}" />
I would like to be able to click this button to close any progress unit, in case it blocks the users view of any controls beneath it. With my current implementation this is not possible as my ListView currently is marked with IsHitTestVisible="False" . That means all controls under it also ignores the hit test, even if I set the buttons IsHitTestVisible to true. That means the button cannot be clicked by the mouse.
How can I make the button work on my progress unit and still have them floating?
So far:
- I have experimented with overriding the hittest of the listview, so I can ignore hittest in code but allow the button to be pressed. This did not work, but I am still looking into this.
- I have tried fiddling with the ZIndex on the Button, but if the listview ZIndex is lower that the rest, then buttons inside it will of cause also be behind it, no matter the buttons ZIndex. Its a part of the ListView.
- I have also looked into the Adorner layer. I find that this could probably work, but it will require a complete rewrite of the logic and as I understand it is not really what it is meant for and will be very complicated.
Any suggestions is very welcome. I am 99% done, I just need the last little piece of the puzzle.
Solution/Workaround
So browsing some more and looking a bit into the links in the replies, I came up with a solution. I found it while browsing but to be honest i forgot where from. Anyway, the first thing i did was taking a part of @Gerry Schmitz advice and remove the z indexs. Then wil browsing @Richards supplied links for the n'th time i came a cross the workaround/solution.
I added a canvas as the first item and moved listview control in there. The canvas was then set to align content to the bottom and then i anchored the listview to the bottom of the canvas. Code looks like this:
<Canvas Grid.Row="1" Grid.RowSpan="2" VerticalAlignment="Bottom">
<ListView x:Name="ProgressListView" ItemsSource="{Binding ProgressCollection}" Background="Transparent" Canvas.Bottom="0" BorderThickness="0">
</ListView>
</Canvas>
This produces some what the result i was expecting. The progress controls is now fully responsive as I am no longer disabling the hittest. And the controls underneath the canvas is responding to mouse events. The reason this works is that the listview control is almost hidden when no progresses are shown. I tiny fraction of the ui in the corner is where the listview is. I could probably enable and disable the hittest in those conditions, but for now i think it is fine.
The reason i am calling this a work around is that when progresses are shown, ei more that 1, the space between the progress controls is not really a space and the mouse event does not sip through to the underlying controls. But we are also talking about 3-4 pixels in width, so only if a user is trying to click between something that is blocking for 5 seconds, then this becomes a problem. I think this will work for now. I still have some styling to do, but the close button now works as expected.
modified 11-Aug-23 4:01am.
|
|
|
|
|
|
I edited my question. For the original question, you are correct. I can't. I found that out and also found the same stackoverflow link you have posted. So my revised question, is now: How can I make the button work on my progress unit and still have them floating?
|
|
|
|
|
You don't need to change the zorder to put it "on top"; you just span the whole grid and then position it the way you want and add it to the (XAML) visual tree last. Or put a canvas behind it for abolute positioning. The button can be placed anywhere relative to the progress "widget" using the same priciples. As for "hit testable", you can "swallow" clicks anytime it simpifies things. (e.Handled = true or false).
(If you can "close" the widget, it begs the question: how do you open it. Maybe the button should be on a top or side "command bar": an enable / disable toggle).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I'm working on an app that has two repository projects.
The first is part of my framework and is called ApplicationSecurity. It has Users, Rights, Encryption, etc. It's designed to be generic and used in any app. It expects an instance of an EF DBContext to be passed into the CTOR
The second repo project is for my app itself. Its tables are app specific. The DBContext resides in this project
So, I build the DBContext in this second project, and used it in both.
In my App.cs CTOR I have:
public App()
{
AppHost = Host.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<IEventAggregator, EventAggregator>();
services.AddSingleton<IApplicationSecurity, ApplicationSecurity>();
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<MainWindowView>();
services.AddSingleton<LoginViewModel>();
services.AddSingleton<LoginView>();
})
.Build();
}
[ ] How do I include my DBContext here?
[ ] My ApplicationSecurity class needs an instance of the DBContext class. How can I pass a reference to a DBContext into the ApplicationSecurity CTOR?
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
|
OK, so I now have
AppHost = Host.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddDbContext<MooseDBContext>(options =>
{
options.UseSqlServer(_connString);
});
services.AddSingleton<IEventAggregator, EventAggregator>();
services.AddSingleton<IApplicationSecurity, ApplicationSecurity>();
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<MainWindowView>();
services.AddSingleton<LoginViewModel>();
services.AddSingleton<LoginView>();
})
.Build();
}
But the ApplicationSecurity class needs an instance of MyDbContext. How do I pass that in?
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
modified 25-Jul-23 19:13pm.
|
|
|
|
|
Add it as a constructor parameter.
Or are you saying that the ApplicationSecurity is defined in an assembly which doesn't have a reference to the assembly where the MooseDBContext is defined?
If that's the case, then you probably want the context to implement an interface:
public interface IApplicationSecurityContext
{
DbSet<YourEntityType> YourEntityTypes { get; }
}
public class ApplicationSecurity : IApplicationSecurity
{
public ApplicationSecurity(IApplicationSecurityContext context)
{
ArgumentNullException.ThrowIfNull(context);
Context = context;
}
private IApplicationSecurityContext Context { get; }
...
}
public class MooseDBContext : DbContext, IApplicationSecurityContext
{
...
} Then register the interfaces as services:
services.AddDbContext<MooseDBContext>(options =>
{
options.UseSqlServer(_connString);
});
services.AddScoped<IApplicationSecurityContext>(sp => sp.GetRequiredService<MooseDBContext>());
You could even create a utility method to automatically register all interfaces implemented by your context:
public static IServiceCollection AddContextInterfaces<TContext>(this IServiceCollection services) where TContext : DbContext
{
ArgumentNullException.ThrowIfNull(services);
foreach (Type t in typeof(TContext).GetInterfaces().Except(typeof(DbContext).GetInterfaces()))
{
services.AddScoped(t, sp => sp.GetRequiredService<TContext>());
}
return services;
}
...
services.AddDbContext<MooseDBContext>(options =>
{
options.UseSqlServer(_connString);
});
services.AddContextInterfaces<MooseDBContext>();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, that seems to work fine.
My class now looks like this:
using Marois.Framework.Core.AppSecurity.Repository;
using Marois.Framework.Core.Crypto;
using Marois.Framework.Core.Shared;
using Microsoft.EntityFrameworkCore;
namespace Marois.Framework.Core.AppSecurity.Service
{
public class ApplicationSecurity : IApplicationSecurity
{
#region Private Fields
private IApplicationSecurityContext _context { get; }
#endregion
#region CTOR
public ApplicationSecurity(IApplicationSecurityContext context)
{
ArgumentNullException.ThrowIfNull(nameof(context));
_context = context;
}
#endregion
#region Public Methods
public Task<UserEntity> LoginAsync(CredentialsEntity credentials)
{
UserEntity? results = null;
ArgumentNullException.ThrowIfNull(nameof(credentials));
var t = Task.Run(() =>
{
var userRepo = new AppSecurityRepository<UserEntity>((DbContext)_context);
var user = userRepo.Find(x => x.UserName == credentials.UserName);
if (Cryptography.VerifyHash(credentials.Password, user.Password, user.Hash))
{
results = user;
}
return results;
});
return t;
}
#endregion
}
}
In the Login method, would you create an instance of the repo, or create it in the CTOR and persist it?
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
It's a dependency, so I'd be inclined to inject the repo rather than the context.
NB: Entity Framework supports asynchronous database queries, so it would be better to offer a FindAsync method on the repo, and get rid of the Task.Run call.
public class ApplicationSecurity : IApplicationSecurity
{
private AppSecurityRepository<UserEntity> _userRepo { get; }
public ApplicationSecurity(AppSecurityRepository<UserEntity> userRepo)
{
ArgumentNullException.ThrowIfNull(nameof(userRepo));
_userRepo = userRepo;
}
public async Task<UserEntity> LoginAsync(CredentialsEntity credentials)
{
var user = await _userRepo.FindAsync(x => x.UserName == credentials.UserName);
if (user is null) return null;
return Cryptography.VerifyHash(credentials.Password, user.Password, user.Hash) ? user : null;
}
} NB2: Why does your user entity have both a Password and a Hash property? I'd expect to see a "protected password" property, and possibly a "salt" property, depending on whether the salt is stored as a separate column or combined with the password hash.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Is there any way to specify a text value when either all items or no items are checked?
In my case I'm using the CheckcComboBox in a report arguments window, so selecting none is the same as all. What I want is to show the word 'All' by default. If any items are selected, then I'd like it to work as it does and show a comma delimited list of checked items.
I have IsSelectAllActive = true in the XAML. I've also tried setting the Text property in the COllectionChanged event. Neither worked.
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
modified 21-Jun-23 0:33am.
|
|
|
|
|
There's nothing obvious in the (rather limited) documentation[^]; you might need to raise an issue with them[^].
Or, if you've paid for the "plus" edition, use their "priority support" system.
NB: The "free" edition no longer supports commercial use[^]. If you're using it in anything other than a personal or internal-use product, they expect you to pay for it. However, there are a few forks from before the license change which are still properly "free".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Wonderful. Thanks
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
I need to load a large set of images and let the user pick from them. The user will select a folder, and the list should load. A view like this[^] is what I'd like it to look like.
The user should be able to filter the types of images to load. Preferable, I'd like to be able to have tabs for each folder so they can load multiple folders at once.
I'm not sure of the right container to use for this. Would a VirtualizingWrapPanel work for this?
Also, what's the right way to load the list? When the user selects the folder, I'd like it to start loading right away. Getting a list of file names is easy, but then I would probably need some kind of model class to bind to the list.
I'd like to hear what you guys think.
Thanks
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
I have a WPF that's branded four ways, say App1, App2, App3, and App4.
I change the name of the output assembly like this:
<AssemblyName Condition="'$(Configuration)' == 'Release App1'">App1</AssemblyName>
<AssemblyName Condition="'$(Configuration)' == 'Release App2'">App2</AssemblyName>
<AssemblyName Condition="'$(Configuration)' == 'Release App3'">App3</AssemblyName>
<AssemblyName Condition="'$(Configuration)' == 'Release App4'">App4</AssemblyName>
This results in the compiled assembly being named according to the brand.
I have images all over the app like this:
<Image x:Name="myImage"
Stretch="None"
Width="15"
Height="15"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Source="/App1;component/Images/My_Image.png" />
In some cases, in Release builds, the images fail to appear. From what I can see, in Release builds the source can't find the assembly name, so the image fails to load. I verified this by renaming all of the output assemblies in the <assemblyname> tags above to "App1" and it works.
So I've implemented code like this:
private BitmapImage _MyImage;
public BitmapImage MyImage
{
get { return _MyImage; }
set
{
if (_MyImage != value)
{
_MyImage = value;
RaisePropertyChanged("MyImage");
}
}
}
and
private void SetupBranding()
{
var imageFolder = "";
if BRAND_APP1
imageFolder = "App1";
elif BRAND_APP2
imageFolder = "App2";
elif BRAND_APP3
imageFolder = "App3";
elif BRAND_APP4
imageFolder = "App4";
<h1>endif</h1>
string assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
var path = $"/{assemblyName};component/Images/Brand/{imageFolder}/My_Image.png";
MyImage = new BitmapImage(new Uri(path, UriKind.Relative));
}
This seems to work fine, but I have do do this anywhere I want to use brand-specific images. I'm wondering of there's a better way? Is there a way to handle hard coded pack URI such has:
Source="/App1;component/Images/My_Image.png"
One other concern is that, while most of this is done in the Windows and Views, there are some URI's specified in styles.
Thanks
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
Use relative Pack URI's.
Pack URIs - WPF .NET Framework | Microsoft Learn
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Good morning all,
been writing a little program that when you put a spotify playlist id in it will get the whole playlist
want the name and total songs in the playlist mainly so all songs in the playlist and then total count of all songs
with a bit of hard work managed to get it to deserialize the content but cant seem to get it to return that
what i have currently is this,
so it goes though and get as far as here,
json data returned from spotify api
put it in pastebin link as contains a lot of data
then thought i would use json2c#
to create my structure for me,
and have this in a playlist.cs
<pre lang="C#"><pre>using System;
using System.Collections.Generic;
using System.Text;
namespace Dark_Admin_Panel.Model
{
public class Playlist
{
public class AddedBy
{
public ExternalUrls external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Album
{
public string album_type { get; set; }
public List<Artist> artists { get; set; }
public List<string> available_markets { get; set; }
public ExternalUrls external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public List<Image> images { get; set; }
public string name { get; set; }
public string release_date { get; set; }
public string release_date_precision { get; set; }
public int total_tracks { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Artist
{
public ExternalUrls external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public string name { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class ExternalIds
{
public string isrc { get; set; }
}
public class ExternalUrls
{
public string spotify { get; set; }
}
public class Followers
{
public object href { get; set; }
public int total { get; set; }
}
public class Image
{
public int height { get; set; }
public string url { get; set; }
public int width { get; set; }
}
public class Item
{
public DateTime added_at { get; set; }
public AddedBy added_by { get; set; }
public bool is_local { get; set; }
public object primary_color { get; set; }
public Track track { get; set; }
public VideoThumbnail video_thumbnail { get; set; }
}
public class Owner
{
public string display_name { get; set; }
public ExternalUrls external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Root
{
public bool collaborative { get; set; }
public string description { get; set; }
public ExternalUrls external_urls { get; set; }
public Followers followers { get; set; }
public string href { get; set; }
public string id { get; set; }
public List<Image> images { get; set; }
public string name { get; set; }
public Owner owner { get; set; }
public object primary_color { get; set; }
public bool @public { get; set; }
public string snapshot_id { get; set; }
public Tracks tracks { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Track
{
public Album album { get; set; }
public List<Artist> artists { get; set; }
public List<string> available_markets { get; set; }
public int disc_number { get; set; }
public int duration_ms { get; set; }
public bool episode { get; set; }
public bool @explicit { get; set; }
public ExternalIds external_ids { get; set; }
public ExternalUrls external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public bool is_local { get; set; }
public string name { get; set; }
public int popularity { get; set; }
public string preview_url { get; set; }
public bool track { get; set; }
public int track_number { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Tracks
{
public string href { get; set; }
public List<Item> items { get; set; }
public int limit { get; set; }
public object next { get; set; }
public int offset { get; set; }
public object previous { get; set; }
public int total { get; set; }
}
public class VideoThumbnail
{
public object url { get; set; }
}
}
}
and is called via the spotifySearch methord
<pre>using System;
using System.Collections.Generic;
using System.Reflection.Metadata;
using System.Text;
using static Dark_Admin_Panel.Model.SpotifySearch;
namespace Dark_Admin_Panel.Model
{
public class SpotifySearch
{
public class ExternalUrls
{
public string spotify { get; set; }
}
public class Followers
{
public object href { get; set; }
public int total { get; set; }
}
public class ImageSP
{
public int width { get; set; }
public string url { get; set; }
public int height { get; set; }
}
public class Item
{
public ExternalUrls external_urls { get; set; }
public Followers followers { get; set; }
public List<string> genres { get; set; }
public string id { get; set; }
public List<ImageSP> images { get; set; }
public string name { get; set; }
public int popularity { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Artists
{
public string href { get; set; }
public List<Item> items { get; set; }
public int limit { get; set; }
}
public class PlaylistItem
{
public ExternalUrls external_urls { get; set; }
public string id { get; set; }
public string name { get; set; }
public string type { get; set; }
public List<ImageSP> images { get; set; }
public Tracks tracks { get; set; }
public string uri { get; set; }
}
public class PlaylistContainer
{
public string href { get; set; }
public List<PlaylistItem> items { get; set; }
public int total { get; set; }
public int limit { get; set; }
}
public class Tracks
{
public string href { get; set; }
public int total { get; set; }
}
public class SpotifyResult
{
public PlaylistContainer playlists { get; set; }
public class AddedBy
{
public ExternalUrls external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Album
{
public string album_type { get; set; }
public List<Artist> artists { get; set; }
public List<string> available_markets { get; set; }
public ExternalUrls external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public List<Image> images { get; set; }
public string name { get; set; }
public string release_date { get; set; }
public string release_date_precision { get; set; }
public int total_tracks { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Artist
{
public ExternalUrls external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public string name { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class ExternalIds
{
public string isrc { get; set; }
}
public class ExternalUrls
{
public string spotify { get; set; }
}
public class Followers
{
public object href { get; set; }
public int total { get; set; }
}
public class Image
{
public int height { get; set; }
public string url { get; set; }
public int width { get; set; }
}
public class Item
{
public DateTime added_at { get; set; }
public AddedBy added_by { get; set; }
public bool is_local { get; set; }
public object primary_color { get; set; }
public Track track { get; set; }
public VideoThumbnail video_thumbnail { get; set; }
}
public class Owner
{
public string display_name { get; set; }
public ExternalUrls external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Root
{
public bool collaborative { get; set; }
public string description { get; set; }
public ExternalUrls external_urls { get; set; }
public Followers followers { get; set; }
public string href { get; set; }
public string id { get; set; }
public List<Image> images { get; set; }
public string name { get; set; }
public Owner owner { get; set; }
public object primary_color { get; set; }
public bool @public { get; set; }
public string snapshot_id { get; set; }
public Tracks tracks { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Track
{
public Album album { get; set; }
public List<Artist> artists { get; set; }
public List<string> available_markets { get; set; }
public int disc_number { get; set; }
public int duration_ms { get; set; }
public bool episode { get; set; }
public bool @explicit { get; set; }
public ExternalIds external_ids { get; set; }
public ExternalUrls external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public bool is_local { get; set; }
public string name { get; set; }
public int popularity { get; set; }
public string preview_url { get; set; }
public bool track { get; set; }
public int track_number { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Tracks
{
public string href { get; set; }
public List<Item> items { get; set; }
public int limit { get; set; }
public object next { get; set; }
public int offset { get; set; }
public object previous { get; set; }
public int total { get; set; }
}
public class VideoThumbnail
{
public object url { get; set; }
}
public class SpotifySearch
{
public class ExternalUrls
{
public string spotify { get; set; }
}
public class Followers
{
public object href { get; set; }
public int total { get; set; }
}
public class ImageSP
{
public int width { get; set; }
public string url { get; set; }
public int height { get; set; }
}
public class Item
{
public ExternalUrls external_urls { get; set; }
public Followers followers { get; set; }
public List<string> genres { get; set; }
public string id { get; set; }
public List<ImageSP> images { get; set; }
public string name { get; set; }
public int popularity { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Artists
{
public string href { get; set; }
public List<Item> items { get; set; }
public int limit { get; set; }
}
public class PlaylistItem
{
public ExternalUrls external_urls { get; set; }
public string id { get; set; }
public string name { get; set; }
public string type { get; set; }
public List<ImageSP> images { get; set; }
public Tracks tracks { get; set; }
public string uri { get; set; }
}
public class PlaylistContainer
{
public string href { get; set; }
public List<PlaylistItem> items { get; set; }
public int total { get; set; }
public int limit { get; set; }
}
public class Tracks
{
public string href { get; set; }
public int total { get; set; }
}
public class SpotifyResult
{
public PlaylistContainer playlists { get; set; }
}
}
}
}
}
then when the item is searched it uses
search helper
and this is where it returns nothing
however the responce.Content returns all the values,
search helper
<pre>public static SpotifySearch.SpotifyResult SearchArtistOrSong(string searchword)
{
var client = new RestClient("https://api.spotify.com/v1/playlists");
client.AddDefaultHeader("Authorization", $"Bearer {token.access_token}");
var request = new RestRequest($"{searchword}", Method.Get);
var response = client.Execute(request);
if (response.IsSuccessful)
{
var result = JsonConvert.DeserializeObject<SpotifySearch.SpotifyResult>(response.Content);
return result;
}
else
{
return null;
}
}
and the mainwindow.cs
<pre> private void elfentext_KeyUp(object sender, KeyEventArgs e)
{
var result = SearchHelper.SearchArtistOrSong(elfentext.Text);
if (result == null)
{
return;
}
var listArtist = new List<SpotifySearch.PlaylistItem>();
if (result?.playlists?.items != null)
{
foreach (var item in result.playlists.items)
{
var images = item.images.Any() ? item.images : new List<SpotifySearch.ImageSP>();
listArtist.Add(new SpotifySearch.PlaylistItem()
{
external_urls = item.external_urls,
id = item.id,
name = item.name,
type = item.type,
images = images,
tracks = item.tracks,
uri = item.uri
});
}
}
elfenlist.ItemsSource = listArtist;
}
i managed to get artist working fine before but just playlist returns so much i just not quite sure what i am doing wrong any help would be so much appreciated
thanks in advance elfenliedtopfan5
|
|
|
|
|
You have asked this in a forum dedicated to WPF. Your post has nothing to do with this. You should ask this in Q&A.
|
|
|
|
|
elfenliedtopfan5 wrote: what i am doing wrong
Perhaps something is eating an exception?
Not clear how you determined that the response content is valid json.
You can also experiment (test) by populating everything in your json objects. Then serialize them to a string. Output that (so you have an example) then deserialize the same thing.
|
|
|
|
|