我想从矩形照片制作一个居中的圆形图像.照片的尺寸未知.通常它是一个矩形形式.我尝试了很多方法:
CSS:
.image-cropper {
max-width: 100px;
height: auto;
position: relative;
overflow: hidden;
}
.image-cropper img{
display: block;
margin: 0 auto;
height: auto;
width: 150%;
margin: 0 0 0 -20%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-ms-border-radius: 50%;
-o-border-radius: 50%;
border-radius: 50%;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="image-cropper">
<img src="http://www.electricvelocity.com.au/Upload/Blogs/smart-e-bike-side_2.jpg" class="rounded" />
</div>
Run Code Online (Sandbox Code Playgroud) 我正在使用带有 TypeScript 的 react-router v5.1 并具有以下路由配置:
<Router basename="/" hashType="slash">
<Switch>
<Route path="/token/:tokenName">
<TokenPage />
</Route>
</Switch>
</Router>
Run Code Online (Sandbox Code Playgroud)
我尝试访问组件中的 url 参数(tokenName),使用 useParams 钩子,如下所示:
const TokenPage: FC<TokenPageProps> = props => {
const { tokenName } = useParams()
...
}
Run Code Online (Sandbox Code Playgroud)
但是,打字稿认为tokenNameparam 可以是未定义的:
这是没有意义的,因为如果 URL 中缺少参数,则反应路由器将不匹配此路由。
在这种情况下,我该如何解决打字问题?
我目前正在使用SignalR在服务器和服务器本身产生的多个独立进程之间进行通信.Server和Client都用C#编码.我正在使用SignalR 2.2.0.0在服务器端,我使用OWIN来运行服务器.我也使用LightInject作为IoC容器.
这是我的代码:
public class AgentManagementStartup
{
public void ConfigurationOwin(IAppBuilder app, IAgentManagerDataStore dataStore)
{
var serializer = new JsonSerializer
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
};
var container = new ServiceContainer();
container.RegisterInstance(dataStore);
container.RegisterInstance(serializer);
container.Register<EventHub>();
container.Register<ManagementHub>();
var config = container.EnableSignalR();
app.MapSignalR("", config);
}
}
Run Code Online (Sandbox Code Playgroud)
在客户端,我这样注册:
public async Task Connect()
{
try
{
m_hubConnection = new HubConnection(m_serverUrl, false);
m_hubConnection.Closed += OnConnectionClosed;
m_hubConnection.TraceLevel = TraceLevels.All;
m_hubConnection.TraceWriter = Console.Out;
var serializer = m_hubConnection.JsonSerializer;
serializer.TypeNameHandling = TypeNameHandling.Auto;
serializer.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
m_managementHubProxy …Run Code Online (Sandbox Code Playgroud) 这是我的Interval定义:
m_interval = Observable.Interval(TimeSpan.FromSeconds(5), m_schedulerProvider.EventLoop)
.ObserveOn(m_schedulerProvider.EventLoop)
.Select(l => Observable.FromAsync(DoWork))
.Concat()
.Subscribe();
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我提供ISchedulerin Interval和ObserveOnfrom,SchedulerProvider以便我可以更快地进行单元测试(TestScheduler.AdvanceBy).另外,DoWork是一种async方法.
在我的特定情况下,我希望DoWork每5秒调用一次该函数.这里的问题是我希望5秒是DoWork另一个结束和开始之间的时间.因此,如果DoWork执行时间超过5秒,假设为10秒,则第一次呼叫为5秒,第二次呼叫为15秒.
不幸的是,以下测试证明它不像那样:
[Fact]
public void MultiPluginStatusHelperShouldWaitForNextQuery()
{
m_queryHelperMock
.Setup(x => x.CustomQueryAsync())
.Callback(() => Thread.Sleep(10000))
.Returns(Task.FromResult(new QueryCompletedEventData()))
.Verifiable()
;
var multiPluginStatusHelper = m_container.GetInstance<IMultiPluginStatusHelper>();
multiPluginStatusHelper.MillisecondsInterval = 5000;
m_testSchedulerProvider.EventLoopScheduler.AdvanceBy(TimeSpan.FromMilliseconds(5000).Ticks);
m_testSchedulerProvider.EventLoopScheduler.AdvanceBy(TimeSpan.FromMilliseconds(5000).Ticks);
m_queryHelperMock.Verify(x => x.CustomQueryAsync(), Times.Once);
}
Run Code Online (Sandbox Code Playgroud)
在DoWork调用CustomQueryAsync和测试失败说的就是被称为两次.它应该只被调用一次,因为强制延迟.Callback(() => Thread.Sleep(1000)).
我在这做错了什么?
我的实际实现来自这个例子.
假设我在C++中有以下结构
struct Base
{
USHORT size;
}
struct Inherited : public Base
{
BYTE type;
}
Run Code Online (Sandbox Code Playgroud)
我想Inherited在C#中编组,但结构继承在C#中不起作用.正在做以下适当的事情吗?
public interface IBase
{
ushort Size { get; set; }
}
[StructLayout(LayoutKind.Sequential)]
public struct Inherited : IBase
{
public ushort Size { get; set; }
public byte Type { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我在这里简化了问题,结构更大,难以验证结果.此外,结构来自另一个不太好的文档,使得验证结果更加困难.在C++中使用继承时,是子结构之前还是之后的基类字段?
我正在使用它IBase作为强制基本字段存在的方式.
不幸的是,我无法控制C++方面(我与之集成的外部系统的SDK).
我想在画布上显示多个图像.我需要在画布中以不同的方式定位它们.我为我的图像上了一堂课:
class MapItem:Image
{
public int DistanceToTop { get; set; }
public int DistanceToLeft { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的XAML看起来像这样:
<UserControl.DataContext>
<Map:MapViewModel/>
</UserControl.DataContext>
<ItemsControl ItemsSource="{Binding All}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="Image">
<Setter Property="Canvas.Left" Value="{Binding DistanceToLeft}" />
<Setter Property="Canvas.Top" Value="{Binding DistanceToTop}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
我的ViewModel用作DataContext:
class MapViewModel : ViewModelBase
{
public ObservableCollection<MapItem> All { get; set; }
public MapViewModel()
{
All = new ObservableCollection<MapItem>();
var wSource = new BitmapImage(new Uri(@"ImagePath"));
var wImage = new MapItem { …Run Code Online (Sandbox Code Playgroud) 为什么我的方法GetList()在linq语句后返回null?
public static List<MyType> GetListOfAllLocations()
{
var DistinctList = ListWith25Elements.GroupBy(x => x.id).Select(y => y.First());
return DistinctList as List<MyType>
}
Run Code Online (Sandbox Code Playgroud)
...
foreach(MyType mt in GetListOfAllLocations())... // this is null?!?!
Run Code Online (Sandbox Code Playgroud) c# ×4
c++ ×1
css ×1
distinct ×1
html ×1
inheritance ×1
itemscontrol ×1
light-inject ×1
linq ×1
list ×1
marshalling ×1
owin ×1
react-router ×1
signalr ×1
struct ×1
types ×1
typescript ×1
unit-testing ×1
var ×1
wpf ×1
xaml ×1